diff --git a/src/renderer/widgets/CreateWallet/lib/types.ts b/src/renderer/widgets/CreateWallet/lib/types.ts index 3429543aad..a27929307a 100644 --- a/src/renderer/widgets/CreateWallet/lib/types.ts +++ b/src/renderer/widgets/CreateWallet/lib/types.ts @@ -34,4 +34,5 @@ export interface SignatoryInfo { index: number; name: string; address: string; + walletId: string; } diff --git a/src/renderer/widgets/CreateWallet/model/__tests__/flow-model.test.ts b/src/renderer/widgets/CreateWallet/model/__tests__/flow-model.test.ts index 94262e8722..a0ef556ed5 100644 --- a/src/renderer/widgets/CreateWallet/model/__tests__/flow-model.test.ts +++ b/src/renderer/widgets/CreateWallet/model/__tests__/flow-model.test.ts @@ -46,11 +46,16 @@ describe('widgets/CreateWallet/model/form-model', () => { await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 0, name: signerWallet.name, address: toAddress(signerWallet.accounts[0].accountId) }, + params: { + index: 0, + name: signerWallet.name, + address: toAddress(signerWallet.accounts[0].accountId), + walletId: '1', + }, }); await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 1, name: 'Alice', address: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY' }, + params: { index: 1, name: 'Alice', address: '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY', walletId: '1' }, }); await allSettled(flowModel.events.signerSelected, { scope, params: signerWallet.accounts[0] }); diff --git a/src/renderer/widgets/CreateWallet/model/__tests__/form-model.test.ts b/src/renderer/widgets/CreateWallet/model/__tests__/form-model.test.ts index 5187e65b21..6eb98bb001 100644 --- a/src/renderer/widgets/CreateWallet/model/__tests__/form-model.test.ts +++ b/src/renderer/widgets/CreateWallet/model/__tests__/form-model.test.ts @@ -69,11 +69,11 @@ describe('widgets/CreateWallet/model/form-model', () => { await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 0, name: 'test', address: toAddress(signerWallet.accounts[0].accountId) }, + params: { index: 0, name: 'test', address: toAddress(signerWallet.accounts[0].accountId), walletId: '1' }, }); await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 1, name: 'Alice', address: toAddress(signatoryWallet.accounts[0].accountId) }, + params: { index: 1, name: 'Alice', address: toAddress(signatoryWallet.accounts[0].accountId), walletId: '1' }, }); await allSettled(formModel.$createMultisigForm.fields.threshold.onChange, { scope, params: 2 }); @@ -112,11 +112,11 @@ describe('widgets/CreateWallet/model/form-model', () => { await allSettled(formModel.$createMultisigForm.fields.chain.onChange, { scope, params: testChain }); await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 0, name: 'test', address: toAddress(signerWallet.accounts[0].accountId) }, + params: { index: 0, name: 'test', address: toAddress(signerWallet.accounts[0].accountId), walletId: '1' }, }); await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 1, name: 'Alice', address: toAddress(signatoryWallet.accounts[0].accountId) }, + params: { index: 1, name: 'Alice', address: toAddress(signatoryWallet.accounts[0].accountId), walletId: '1' }, }); await allSettled(formModel.$createMultisigForm.fields.threshold.onChange, { scope, params: 2 }); diff --git a/src/renderer/widgets/CreateWallet/model/__tests__/signatory-model.test.ts b/src/renderer/widgets/CreateWallet/model/__tests__/signatory-model.test.ts index 720f35ae15..e955a97f5c 100644 --- a/src/renderer/widgets/CreateWallet/model/__tests__/signatory-model.test.ts +++ b/src/renderer/widgets/CreateWallet/model/__tests__/signatory-model.test.ts @@ -20,12 +20,12 @@ describe('widgets/CreateWallet/model/signatory-model', () => { await allSettled(signatoryModel.events.addSignatory, { scope, - params: { name: 'Alice', address: toAddress(signerWallet.accounts[0].accountId) }, + params: { name: 'Alice', address: toAddress(signerWallet.accounts[0].accountId), walletId: '1' }, }); await allSettled(signatoryModel.events.addSignatory, { scope, - params: { name: 'test', address: toAddress(signerWallet.accounts[0].accountId) }, + params: { name: 'test', address: toAddress(signerWallet.accounts[0].accountId), walletId: '1' }, }); expect(scope.getState(signatoryModel.$signatories).length).toEqual(2); @@ -40,7 +40,7 @@ describe('widgets/CreateWallet/model/signatory-model', () => { await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 0, name: 'test', address: toAddress(signerWallet.accounts[0].accountId) }, + params: { index: 0, name: 'test', address: toAddress(signerWallet.accounts[0].accountId), walletId: '1' }, }); expect(scope.getState(signatoryModel.$signatories).length).toEqual(1); @@ -60,14 +60,14 @@ describe('widgets/CreateWallet/model/signatory-model', () => { await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 1, name: 'Alice', address: toAddress(signatoryWallet.accounts[0].accountId) }, + params: { index: 1, name: 'Alice', address: toAddress(signatoryWallet.accounts[0].accountId), walletId: '1' }, }); expect(scope.getState(signatoryModel.$ownedSignatoriesWallets)?.length).toEqual(0); await allSettled(signatoryModel.events.changeSignatory, { scope, - params: { index: 0, name: 'test', address: toAddress(signerWallet.accounts[0].accountId) }, + params: { index: 0, name: 'test', address: toAddress(signerWallet.accounts[0].accountId), walletId: '1' }, }); expect(scope.getState(signatoryModel.$ownedSignatoriesWallets)?.length).toEqual(1); }); diff --git a/src/renderer/widgets/CreateWallet/model/flow-model.ts b/src/renderer/widgets/CreateWallet/model/flow-model.ts index 74f023ce51..63a20c3c7f 100644 --- a/src/renderer/widgets/CreateWallet/model/flow-model.ts +++ b/src/renderer/widgets/CreateWallet/model/flow-model.ts @@ -69,7 +69,7 @@ const $signer = restore(signerSelected, null).reset(flowFinished const $signerWallet = combine({ signer: $signer, wallets: walletModel.$wallets }, ({ signer, wallets }) => { const res = walletUtils.getWalletFilteredAccounts(wallets, { accountFn: (a) => a.accountId === signer?.accountId, - walletFn: (w) => walletUtils.isValidSignatory(w), + walletFn: (w) => walletUtils.isValidSignatory(w) && w.id === signer?.walletId, }); return res; diff --git a/src/renderer/widgets/CreateWallet/model/signatory-model.ts b/src/renderer/widgets/CreateWallet/model/signatory-model.ts index d361ffd8da..d1de3fd0e3 100644 --- a/src/renderer/widgets/CreateWallet/model/signatory-model.ts +++ b/src/renderer/widgets/CreateWallet/model/signatory-model.ts @@ -12,7 +12,7 @@ const changeSignatory = createEvent(); const deleteSignatory = createEvent(); const getSignatoriesBalance = createEvent(); -const $signatories = createStore[]>([{ name: '', address: '' }]); +const $signatories = createStore[]>([{ name: '', address: '', walletId: '' }]); const $hasDuplicateSignatories = combine($signatories, (signatories) => { const existingKeys: Set
= new Set(); @@ -58,9 +58,9 @@ sample({ sample({ clock: addSignatory, source: $signatories, - fn: (signatories, { name, address }) => { + fn: (signatories, { name, address, walletId }) => { return produce(signatories, (draft) => { - draft.push({ name, address }); + draft.push({ name, address, walletId }); }); }, target: $signatories, @@ -69,12 +69,12 @@ sample({ sample({ clock: changeSignatory, source: $signatories, - fn: (signatories, { index, name, address }) => { + fn: (signatories, { index, name, address, walletId }) => { return produce(signatories, (draft) => { if (index >= draft.length) { - draft.push({ name, address }); + draft.push({ name, address, walletId }); } else { - draft[index] = { name, address }; + draft[index] = { name, address, walletId }; } }); }, diff --git a/src/renderer/widgets/CreateWallet/ui/MultisigWallet/components/SelectSignatories.tsx b/src/renderer/widgets/CreateWallet/ui/MultisigWallet/components/SelectSignatories.tsx index ad2895d39a..7c819cb135 100644 --- a/src/renderer/widgets/CreateWallet/ui/MultisigWallet/components/SelectSignatories.tsx +++ b/src/renderer/widgets/CreateWallet/ui/MultisigWallet/components/SelectSignatories.tsx @@ -12,7 +12,7 @@ export const SelectSignatories = () => { const signatories = useUnit(signatoryModel.$signatories); const onAddSignatoryClick = () => { - signatoryModel.events.addSignatory({ name: '', address: '' }); + signatoryModel.events.addSignatory({ name: '', address: '', walletId: '' }); }; return ( @@ -25,6 +25,7 @@ export const SelectSignatories = () => { isOwnAccount={index === 0} signatoryName={value.name} signatoryAddress={value.address} + selectedWallet={value.walletId} onDelete={signatoryModel.events.deleteSignatory} /> ))} diff --git a/src/renderer/widgets/CreateWallet/ui/MultisigWallet/components/Signatory.tsx b/src/renderer/widgets/CreateWallet/ui/MultisigWallet/components/Signatory.tsx index a0fb27719f..f2ccdb01dc 100644 --- a/src/renderer/widgets/CreateWallet/ui/MultisigWallet/components/Signatory.tsx +++ b/src/renderer/widgets/CreateWallet/ui/MultisigWallet/components/Signatory.tsx @@ -8,7 +8,7 @@ import { performSearch, toAccountId, toAddress, validateAddress } from '@/shared import { CaptionText, Combobox, IconButton, Identicon, Input } from '@/shared/ui'; import { type ComboboxOption } from '@/shared/ui/types'; import { contactModel } from '@/entities/contact'; -import { AddressWithName, WalletIcon, walletModel, walletUtils } from '@/entities/wallet'; +import { AddressWithName, WalletIcon, accountUtils, walletModel, walletUtils } from '@/entities/wallet'; import { filterModel } from '@/features/contacts'; import { walletSelectUtils } from '@/features/wallets/WalletSelect/lib/wallet-select-utils'; import { GroupLabels } from '@/features/wallets/WalletSelect/ui/WalletGroup'; @@ -19,6 +19,7 @@ interface Props { signatoryName: string; signatoryAddress: string; signatoryIndex: number; + selectedWallet: string; isOwnAccount?: boolean; onDelete?: (index: number) => void; } @@ -29,6 +30,7 @@ export const Signatory = ({ isOwnAccount = false, signatoryName, signatoryAddress, + selectedWallet, }: Props) => { const { t } = useI18n(); const [query, setQuery] = useState(''); @@ -54,12 +56,17 @@ export const Signatory = ({ const ownAccountName = walletUtils.getWalletsFilteredAccounts(wallets, { - walletFn: (w) => !walletUtils.isWatchOnly(w) && !walletUtils.isMultisig(w), - accountFn: (a) => toAccountId(signatoryAddress) === a.accountId, + walletFn: (w) => + !walletUtils.isWatchOnly(w) && + !walletUtils.isMultisig(w) && + (!selectedWallet || w.id.toString() === selectedWallet), + accountFn: (a) => + toAccountId(signatoryAddress) === a.accountId && accountUtils.isChainIdMatch(a, chain.value.chainId), })?.[0]?.name || ''; const contactAccountName = contacts.filter((contact) => toAccountId(contact.address) === toAccountId(signatoryAddress))?.[0]?.name || ''; + const displayName = useMemo(() => { const hasDuplicateName = !!ownAccountName && !!contactAccountName; const shouldForceOwnAccountName = hasDuplicateName && isOwnAccount; @@ -95,7 +102,7 @@ export const Signatory = ({ return { value: address, element: , - id: account.accountId, + id: account.walletId.toString(), }; }), ); @@ -153,6 +160,7 @@ export const Signatory = ({ index: signatoryIndex, name: newName, address: signatoryAddress, + walletId: selectedWallet, }); }; @@ -162,12 +170,13 @@ export const Signatory = ({ } }, [displayName]); - const onAddressChange = (newAddress: string) => { - const validatedAddress = validateAddress(newAddress) ? newAddress : ''; + const onAddressChange = (data: ComboboxOption) => { + const validatedAddress = validateAddress(data.value) ? data.value : ''; const fixedAddress = toAddress(validatedAddress, { prefix: chain.value.addressPrefix }); signatoryModel.events.changeSignatory({ index: signatoryIndex, + walletId: data.id, name: signatoryName, address: fixedAddress, }); @@ -210,8 +219,8 @@ export const Signatory = ({ query={query} value={toAddress(signatoryAddress, { prefix: chain.value.addressPrefix })} prefixElement={prefixElement} - onChange={({ value }) => { - onAddressChange(value); + onChange={(data) => { + onAddressChange(data); }} onInput={handleQueryChange} />