From a28570b734e42285b0fb495551f7138f81201d26 Mon Sep 17 00:00:00 2001 From: yanguoyu <841185308@qq.com> Date: Thu, 4 Jan 2024 16:29:20 +0800 Subject: [PATCH] fix: Remove walletId for `get-multisig-config` API 1. Remove walletId for `get-multisig-config` API 2. Disabled `Approve` button when the current wallet can not sign for the multisig config. --- .../src/components/MultisigAddress/hooks.ts | 4 ++-- .../src/components/MultisigAddress/index.tsx | 9 ++++++--- .../neuron-ui/src/services/remote/multisig.ts | 2 +- packages/neuron-wallet/src/controllers/api.ts | 4 ++-- .../neuron-wallet/src/controllers/multisig.ts | 4 ++-- packages/neuron-wallet/src/services/multisig.ts | 16 ++-------------- .../neuron-wallet/src/services/sync-progress.ts | 4 ++-- .../tests/controllers/multisig.test.ts | 4 ++-- .../tests/services/multisig.test.ts | 13 +++++-------- 9 files changed, 24 insertions(+), 36 deletions(-) diff --git a/packages/neuron-ui/src/components/MultisigAddress/hooks.ts b/packages/neuron-ui/src/components/MultisigAddress/hooks.ts index c2e0613d4b..a672164efd 100644 --- a/packages/neuron-ui/src/components/MultisigAddress/hooks.ts +++ b/packages/neuron-ui/src/components/MultisigAddress/hooks.ts @@ -73,12 +73,12 @@ export const useConfigManage = ({ walletId, isMainnet }: { walletId: string; isM [walletId, setEntities] ) useEffect(() => { - getMultisigConfig(walletId).then(res => { + getMultisigConfig().then(res => { if (isSuccessResponse(res) && res.result) { setEntities(res.result) } }) - }, [setEntities, walletId]) + }, [setEntities]) const updateConfig = useCallback( (id: number) => (e: React.SyntheticEvent) => { const { value } = e.target as HTMLInputElement diff --git a/packages/neuron-ui/src/components/MultisigAddress/index.tsx b/packages/neuron-ui/src/components/MultisigAddress/index.tsx index fdfd91c33a..d6d38e702f 100644 --- a/packages/neuron-ui/src/components/MultisigAddress/index.tsx +++ b/packages/neuron-ui/src/components/MultisigAddress/index.tsx @@ -28,10 +28,12 @@ import { ReactComponent as Edit } from 'widgets/Icons/Edit.svg' import { Download, Search } from 'widgets/Icons/icon' import { HIDE_BALANCE, NetworkType } from 'utils/const' import { onEnter } from 'utils/inputDevice' +import getMultisigSignStatus from 'utils/getMultisigSignStatus' import { useSearch, useConfigManage, useExportConfig, useActions, useSubscription } from './hooks' import styles from './multisigAddress.module.scss' +const ApproveKey = 'approve' const tableActions = [ { key: 'info', @@ -46,7 +48,7 @@ const tableActions = [ icon: , }, { - key: 'approve', + key: ApproveKey, icon: , }, ] @@ -56,7 +58,7 @@ const MultisigAddress = () => { useOnLocaleChange(i18n) useExitOnWalletChange() const { - wallet: { id: walletId }, + wallet: { id: walletId, addresses }, chain: { networkID }, settings: { networks = [] }, } = useGlobalState() @@ -281,6 +283,7 @@ const MultisigAddress = () => { dataIndex: 'action', align: 'left', render(_, __, item) { + const { canSign } = getMultisigSignStatus({ multisigConfig: item, addresses }) return (
{ key={key} data-key={key} onClick={onClickItem(item)} - disabled={disabled} + disabled={key === ApproveKey ? !canSign || disabled : disabled} > {icon} {t(label)} diff --git a/packages/neuron-ui/src/services/remote/multisig.ts b/packages/neuron-ui/src/services/remote/multisig.ts index 79332443d4..5b5ce1579a 100644 --- a/packages/neuron-ui/src/services/remote/multisig.ts +++ b/packages/neuron-ui/src/services/remote/multisig.ts @@ -29,7 +29,7 @@ export type MultisigConfig = MultisigEntity & { } export const saveMultisigConfig = remoteApi, MultisigEntity>('save-multisig-config') -export const getMultisigConfig = remoteApi('get-multisig-config') +export const getMultisigConfig = remoteApi('get-multisig-config') export const importMultisigConfig = remoteApi('import-multisig-config') export const exportMultisigConfig = remoteApi('export-multisig-config') export const updateMultisigConfig = remoteApi, 'id'>, MultisigEntity>( diff --git a/packages/neuron-wallet/src/controllers/api.ts b/packages/neuron-wallet/src/controllers/api.ts index 0d92bb8294..a9aa17f3a9 100644 --- a/packages/neuron-wallet/src/controllers/api.ts +++ b/packages/neuron-wallet/src/controllers/api.ts @@ -796,8 +796,8 @@ export default class ApiController { return this.#multisigController.deleteConfig(params) }) - handle('get-multisig-config', async (_, walletId: string) => { - return this.#multisigController.getConfig(walletId) + handle('get-multisig-config', async () => { + return this.#multisigController.getConfig() }) handle('import-multisig-config', async (_, walletId: string) => { diff --git a/packages/neuron-wallet/src/controllers/multisig.ts b/packages/neuron-wallet/src/controllers/multisig.ts index f77f4b52fc..ea41a69bb1 100644 --- a/packages/neuron-wallet/src/controllers/multisig.ts +++ b/packages/neuron-wallet/src/controllers/multisig.ts @@ -79,8 +79,8 @@ export default class MultisigController { } } - async getConfig(walletId: string) { - const result = await this.#multisigService.getMultisigConfig(walletId) + async getConfig() { + const result = await this.#multisigService.getMultisigConfig() return { status: ResponseCode.Success, result, diff --git a/packages/neuron-wallet/src/services/multisig.ts b/packages/neuron-wallet/src/services/multisig.ts index d26b678b17..9c28e92bba 100644 --- a/packages/neuron-wallet/src/services/multisig.ts +++ b/packages/neuron-wallet/src/services/multisig.ts @@ -11,7 +11,6 @@ import NetworksService from './networks' import Multisig from '../models/multisig' import SyncProgress, { SyncAddressType } from '../database/chain/entities/sync-progress' import { NetworkType } from '../models/network' -import WalletService from './wallets' import logger from '../utils/logger' const max64Int = '0x' + 'f'.repeat(16) @@ -21,7 +20,6 @@ export default class MultisigService { .getRepository(MultisigConfig) .createQueryBuilder() .where({ - walletId: multisigConfig.walletId, r: multisigConfig.r, m: multisigConfig.m, n: multisigConfig.n, @@ -69,13 +67,10 @@ export default class MultisigService { return { ...result, ...params } } - async getMultisigConfig(walletId: string) { + async getMultisigConfig() { const result = await getConnection() .getRepository(MultisigConfig) .createQueryBuilder() - .where({ - walletId, - }) .orderBy('id', 'DESC') .getMany() return result @@ -340,14 +335,7 @@ export default class MultisigService { } static async getMultisigConfigForLight() { - const currentWallet = WalletService.getInstance().getCurrent() - const multisigConfigs = await getConnection() - .getRepository(MultisigConfig) - .createQueryBuilder() - .where({ - walletId: currentWallet?.id, - }) - .getMany() + const multisigConfigs = await getConnection().getRepository(MultisigConfig).createQueryBuilder().getMany() return multisigConfigs.map(v => ({ walletId: v.walletId, script: Multisig.getMultisigScript(v.blake160s, v.r, v.m, v.n), diff --git a/packages/neuron-wallet/src/services/sync-progress.ts b/packages/neuron-wallet/src/services/sync-progress.ts index 2d42843bab..7bef4e3fb3 100644 --- a/packages/neuron-wallet/src/services/sync-progress.ts +++ b/packages/neuron-wallet/src/services/sync-progress.ts @@ -27,13 +27,13 @@ export default class SyncProgressService { .createQueryBuilder() .update(SyncProgress) .set({ delete: true }) - .where({ walletId: Not(In(existWalletIds)) }) + .where({ walletId: Not(In(existWalletIds)), addressType: SyncAddressType.Default }) .execute() await getConnection() .createQueryBuilder() .update(SyncProgress) .set({ delete: false }) - .where({ walletId: In(existWalletIds) }) + .where({ walletId: In(existWalletIds), addressType: SyncAddressType.Default }) .execute() } diff --git a/packages/neuron-wallet/tests/controllers/multisig.test.ts b/packages/neuron-wallet/tests/controllers/multisig.test.ts index cd8eedc507..f502c461d5 100644 --- a/packages/neuron-wallet/tests/controllers/multisig.test.ts +++ b/packages/neuron-wallet/tests/controllers/multisig.test.ts @@ -160,8 +160,8 @@ describe('test for multisig controller', () => { }) it('get config', async () => { - await multisigController.getConfig('abcd') - expect(MultiSigServiceMock.prototype.getMultisigConfig).toHaveBeenCalledWith('abcd') + await multisigController.getConfig() + expect(MultiSigServiceMock.prototype.getMultisigConfig).toHaveBeenCalledWith() }) describe('import config', () => { diff --git a/packages/neuron-wallet/tests/services/multisig.test.ts b/packages/neuron-wallet/tests/services/multisig.test.ts index 67c459c820..a661e72b56 100644 --- a/packages/neuron-wallet/tests/services/multisig.test.ts +++ b/packages/neuron-wallet/tests/services/multisig.test.ts @@ -87,8 +87,10 @@ describe('multisig service', () => { await expect(multisigService.saveMultisigConfig(defaultMultisigConfig)).rejects.toThrow() }) it('save success', async () => { - defaultMultisigConfig.walletId = 'walletId1' - const res = await multisigService.saveMultisigConfig(defaultMultisigConfig) + const anotherConfig = MultisigConfig.fromModel(multisigConfigModel) + anotherConfig.lastestBlockNumber = '0x0' + anotherConfig.r = 2 + const res = await multisigService.saveMultisigConfig(anotherConfig) const count = await getConnection() .getRepository(MultisigConfig) .createQueryBuilder() @@ -97,7 +99,6 @@ describe('multisig service', () => { }) .getCount() expect(count).toBe(1) - defaultMultisigConfig.walletId = 'walletId' }) }) @@ -127,12 +128,8 @@ describe('multisig service', () => { }) describe('test get config', () => { - it('no config', async () => { - const configs = await multisigService.getMultisigConfig('noconfigwallet') - expect(configs).toHaveLength(0) - }) it('has config wallet', async () => { - const configs = await multisigService.getMultisigConfig(multisigConfigModel.walletId) + const configs = await multisigService.getMultisigConfig() expect(configs).toHaveLength(1) }) })