Skip to content

Commit

Permalink
Merge branch 'develop' into log-ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Aug 1, 2024
2 parents b7d1a78 + 79a8dc2 commit 940a628
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .ckb-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.116.1
v0.117.0
6 changes: 6 additions & 0 deletions compatible.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"fullVersions": [
"0.117",
"0.116",
"0.115",
"0.114",
Expand All @@ -22,6 +23,7 @@
"compatible": {
"0.111": {
"full": [
"0.117",
"0.116",
"0.115",
"0.114",
Expand All @@ -38,6 +40,7 @@
},
"0.110": {
"full": [
"0.117",
"0.116",
"0.115",
"0.114",
Expand Down Expand Up @@ -70,6 +73,7 @@
},
"0.112": {
"full": [
"0.117",
"0.116",
"0.115",
"0.114",
Expand All @@ -86,6 +90,7 @@
},
"0.114": {
"full": [
"0.117",
"0.116",
"0.115",
"0.114",
Expand All @@ -102,6 +107,7 @@
},
"0.116": {
"full": [
"0.117",
"0.116",
"0.115",
"0.114",
Expand Down
35 changes: 35 additions & 0 deletions packages/neuron-ui/src/containers/Main/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useEffect, useCallback, useState } from 'react'
import { useLocation, NavigateFunction, useNavigate } from 'react-router-dom'
import type { TFunction } from 'i18next'
import { NeuronWalletActions, StateDispatch, AppActions } from 'states/stateProvider/reducer'
import {
updateTransactionList,
Expand All @@ -9,6 +10,7 @@ import {
initAppState,
showGlobalAlertDialog,
updateLockWindowInfo,
dismissGlobalAlertDialog,
} from 'states/stateProvider/actionCreators'

import {
Expand All @@ -18,6 +20,7 @@ import {
setCurrentNetwork,
startNodeIgnoreExternal,
startSync,
replaceWallet,
} from 'services/remote'
import {
DataUpdate as DataUpdateSubject,
Expand Down Expand Up @@ -117,6 +120,7 @@ export const useSubscription = ({
showSwitchNetwork,
lockWindowInfo,
setIsLockDialogShow,
t,
}: {
walletID: string
chain: State.Chain
Expand All @@ -127,6 +131,7 @@ export const useSubscription = ({
showSwitchNetwork: () => void
lockWindowInfo: State.App['lockWindowInfo']
setIsLockDialogShow: (v: boolean) => void
t: TFunction
}) => {
const { pageNo, pageSize, keywords } = chain.transactions

Expand Down Expand Up @@ -318,6 +323,36 @@ export const useSubscription = ({
setIsLockDialogShow(true)
}
break
case 'import-exist-xpubkey': {
if (payload) {
const { existWalletIsWatchOnly, existingWalletId, id: importedWalletId } = JSON.parse(payload)
if (existWalletIsWatchOnly) {
showGlobalAlertDialog({
type: 'warning',
message: t('main.import-exist-xpubkey-dialog.replace-tip'),
action: 'all',
onOk: () => {
replaceWallet({
existingWalletId,
importedWalletId,
}).then(res => {
if (isSuccessResponse(res)) {
dismissGlobalAlertDialog()(dispatch)
navigate(RoutePath.Overview)
}
})
},
})(dispatch)
} else {
showGlobalAlertDialog({
type: 'warning',
message: t('main.import-exist-xpubkey-dialog.delete-tip'),
action: 'ok',
})(dispatch)
}
}
break
}
default: {
break
}
Expand Down
2 changes: 2 additions & 0 deletions packages/neuron-ui/src/containers/Main/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const MainContent = () => {
showSwitchNetwork,
lockWindowInfo,
setIsLockDialogShow,
t,
})

useOnCurrentWalletChange({
Expand Down Expand Up @@ -147,6 +148,7 @@ const MainContent = () => {
action={globalAlertDialog?.action}
type={globalAlertDialog?.type ?? 'success'}
onCancel={onCancelGlobalDialog}
onOk={globalAlertDialog?.onOk}
/>
<Dialog show={isMigrateDialogShow} onCancel={onCancel} title={t('messages.migrate-ckb-data')} showFooter={false}>
{t('messages.rebuild-sync')
Expand Down
4 changes: 4 additions & 0 deletions packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,10 @@
"tip": "Due to insufficient disk space, synchronization has been stopped. <br /> Please allocate more disk space or migrate the data to another disk.",
"continue-sync": "Continue Sync",
"migrate-data": "Migrate Data"
},
"import-exist-xpubkey-dialog": {
"replace-tip": "The watch-wallet has been imported before, would you replace it?",
"delete-tip": "The same original wallet existed. If you want to continue with the import, please delete it.."
}
},
"cell-manage": {
Expand Down
4 changes: 4 additions & 0 deletions packages/neuron-ui/src/locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,10 @@
"tip": "La sincronización se ha detenido debido a falta de espacio en disco. <br /> Asigne más espacio en disco o migre los datos a otro disco.",
"continue-sync": "Continuar sincronización",
"migrate-data": "Migrar datos"
},
"import-exist-xpubkey-dialog": {
"replace-tip": "El monedero de observación ya ha sido importado antes, ¿desea reemplazarlo?",
"delete-tip": "Existe el mismo monedero original. Si desea continuar con la importación, por favor elimínelo."
}
},
"cell-manage": {
Expand Down
4 changes: 4 additions & 0 deletions packages/neuron-ui/src/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,10 @@
"tip": "En raison d'un espace disque insuffisant, la synchronisation a été interrompue. <br /> Veuillez allouer plus d'espace disque ou migrer les données vers un autre disque.",
"continue-sync": "Continuer la synchronisation",
"migrate-data": "Migration des données"
},
"import-exist-xpubkey-dialog": {
"replace-tip": "Le portefeuille de visualisation a déjà été importé, souhaitez-vous le remplacer?",
"delete-tip": "Le même portefeuille original existe déjà. Si vous souhaitez continuer l'importation, veuillez le supprimer."
}
},
"cell-manage": {
Expand Down
4 changes: 4 additions & 0 deletions packages/neuron-ui/src/locales/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,10 @@
"tip": "由於磁盤空間不足,同步已停止。 <br /> 請分配更多磁盤空間或將數據遷移到其他磁盤。",
"continue-sync": "繼續同步",
"migrate-data": "遷移數據"
},
"import-exist-xpubkey-dialog": {
"replace-tip": "該觀察錢包已被導入過,您想要替換它嗎?",
"delete-tip": "已存在相同的原始錢包。如果您想繼續導入,請刪除它。"
}
},
"cell-manage": {
Expand Down
4 changes: 4 additions & 0 deletions packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,10 @@
"tip": "由于磁盘空间不足,同步已停止。 <br /> 请分配更多磁盘空间或将数据迁移到其他磁盘。",
"continue-sync": "继续同步",
"migrate-data": "迁移数据"
},
"import-exist-xpubkey-dialog": {
"replace-tip": "该观察钱包已被导入过,您想要替换它吗?",
"delete-tip": "已存在相同的原始钱包。如果您想继续导入,请删除它。"
}
},
"cell-manage": {
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-ui/src/types/Subject/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare namespace Command {
| 'sign-verify'
| 'multisig-address'
| 'lock-window'
| 'import-exist-xpubkey'
type Payload = string | null
}

Expand Down
1 change: 0 additions & 1 deletion packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
"subleveldown": "4.1.4",
"tslib": "2.6.3",
"typeorm": "0.3.17",
"undici": "5.28.4",
"uuid": "8.3.2"
},
"devDependencies": {
Expand Down
16 changes: 15 additions & 1 deletion packages/neuron-wallet/src/controllers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ import { UpdateCellLocalInfo } from '../database/chain/entities/cell-local-info'
import { CKBLightRunner } from '../services/light-runner'
import { type OutPoint } from '@ckb-lumos/lumos'
import { updateApplicationMenu } from './app/menu'
import { DuplicateImportWallet } from '../exceptions'
import CommandSubject from '../models/subjects/command'

export type Command = 'export-xpubkey' | 'import-xpubkey' | 'delete-wallet' | 'backup-wallet'
// Handle channel messages from renderer process and user actions.
Expand Down Expand Up @@ -105,7 +107,19 @@ export default class ApiController {
DataUpdateSubject.next({ dataType: 'new-xpubkey-wallet', actionType: 'create' })
})
.catch(error => {
dialog.showMessageBox({ type: 'error', buttons: [], message: error.message })
if (error instanceof DuplicateImportWallet) {
const window = BrowserWindow.getFocusedWindow()
if (window) {
CommandSubject.next({
winID: window.id,
type: 'import-exist-xpubkey',
payload: error.message,
dispatchToUI: true,
})
}
} else {
dialog.showMessageBox({ type: 'error', buttons: [], message: error.message })
}
})
break
}
Expand Down
3 changes: 2 additions & 1 deletion packages/neuron-wallet/src/controllers/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
MainnetAddressRequired,
TestnetAddressRequired,
UnsupportedCkbCliKeystore,
DuplicateImportWallet,
} from '../exceptions'
import AddressService from '../services/addresses'
import TransactionSender from '../services/transaction-sender'
Expand Down Expand Up @@ -338,7 +339,7 @@ export default class WalletsController {
result: wallet,
}
} catch (e) {
if (e instanceof UsedName) {
if (e instanceof UsedName || e instanceof DuplicateImportWallet) {
throw e
}
throw new InvalidJSON()
Expand Down
1 change: 1 addition & 0 deletions packages/neuron-wallet/src/models/subjects/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const CommandSubject = new Subject<{
| 'sign-verify'
| 'multisig-address'
| 'lock-window'
| 'import-exist-xpubkey'
payload: string | null
dispatchToUI: boolean
}>()
Expand Down
14 changes: 12 additions & 2 deletions packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,19 @@ export default class WalletService {
wallet.saveKeystore(props.keystore!)
}

if (this.getAll().find(item => item.extendedKey === props.extendedKey)) {
const existWalletInfo = this.getAll().find(item => item.extendedKey === props.extendedKey)
if (existWalletInfo) {
const existWallet = FileKeystoreWallet.fromJSON(existWalletInfo)
const existWalletIsWatchOnly = existWallet.isHDWallet() && existWallet.loadKeystore().isEmpty()
this.importedWallet = wallet
throw new DuplicateImportWallet(JSON.stringify({ extendedKey: props.extendedKey, id }))
throw new DuplicateImportWallet(
JSON.stringify({
extendedKey: props.extendedKey,
existWalletIsWatchOnly,
existingWalletId: existWallet.id,
id,
})
)
}

this.listStore.writeSync(this.walletsKey, [...this.getAll(), wallet.toJSON()])
Expand Down
5 changes: 2 additions & 3 deletions packages/neuron-wallet/src/utils/ckb-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
PayloadInBatchException,
IdNotMatchedInBatchException,
} from '@ckb-lumos/rpc/lib/exceptions'
import { request } from 'undici'
import CommonUtils from './common'
import { NetworkType } from '../models/network'
import type { RPCConfig } from '@ckb-lumos/rpc/lib/types/common'
Expand Down Expand Up @@ -335,12 +334,12 @@ export class LightRPC extends Base {
return []
}

const res = await request(node.url, {
const res = await fetch(node.url, {
method: 'POST',
body: JSON.stringify(payload),
headers: { 'content-type': 'application/json' },
})
const batchRes = await res.body.json()
const batchRes = await res.json()

if (!Array.isArray(batchRes)) {
return []
Expand Down
18 changes: 8 additions & 10 deletions packages/neuron-wallet/src/utils/rpc-request.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { request } from 'undici'

export const rpcRequest = async <T = any>(
url: string,
options: {
method: string
params?: any
}
): Promise<T> => {
const res = await request(url, {
const res = await fetch(url, {
method: 'POST',
body: JSON.stringify({
id: 0,
Expand All @@ -19,10 +17,10 @@ export const rpcRequest = async <T = any>(
'content-type': 'application/json',
},
})
if (res.statusCode !== 200) {
throw new Error(`indexer request failed with HTTP code ${res.statusCode}`)
if (res.status !== 200) {
throw new Error(`indexer request failed with HTTP code ${res.status}`)
}
const body = await res.body.json()
const body = await res.json()
if (body !== null && typeof body === 'object' && 'result' in body) {
return body?.result as T
}
Expand All @@ -36,7 +34,7 @@ export const rpcBatchRequest = async (
params?: any
}[]
): Promise<any[]> => {
const res = await request(url, {
const res = await fetch(url, {
headers: {
'content-type': 'application/json',
},
Expand All @@ -50,10 +48,10 @@ export const rpcBatchRequest = async (
}))
),
})
if (res.statusCode !== 200) {
throw new Error(`indexer request failed with HTTP code ${res.statusCode}`)
if (res.status !== 200) {
throw new Error(`indexer request failed with HTTP code ${res.status}`)
}
const responseBody = await res.body.json()
const responseBody = await res.json()
if (Array.isArray(responseBody) && responseBody.every(i => 'id' in i)) {
return responseBody.sort((a, b) => a.id - b.id)
}
Expand Down
3 changes: 0 additions & 3 deletions packages/neuron-wallet/tests/controllers/sync-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ jest.doMock('models/subjects/networks', () => {
},
}
})
jest.mock('undici', () => ({
request: () => jest.fn()(),
}))
jest.mock('services/multisig', () => ({
syncMultisigOutput: () => jest.fn(),
}))
Expand Down
Loading

1 comment on commit 940a628

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 10191489583

Please sign in to comment.