diff --git a/src/renderer/entities/wallet/model/wallet-model.ts b/src/renderer/entities/wallet/model/wallet-model.ts index 759babaaf..191ba8ff9 100644 --- a/src/renderer/entities/wallet/model/wallet-model.ts +++ b/src/renderer/entities/wallet/model/wallet-model.ts @@ -219,6 +219,10 @@ const walletCreatedDone = sample({ clock: [walletCreatedFx.doneData, multishardCreatedFx.doneData], }).filter({ fn: nonNullable }); +const walletCreationFail = sample({ + clock: [walletCreatedFx.fail, multishardCreatedFx.fail], +}).filter({ fn: nonNullable }); + sample({ clock: [walletConnectCreated, watchOnlyCreated, multisigCreated, singleshardCreated, proxiedCreated], target: walletCreatedFx, @@ -369,6 +373,7 @@ export const walletModel = { walletConnectCreated, proxiedCreated, walletCreatedDone, + walletCreationFail, selectWallet, updateAccounts, updateWallet, diff --git a/src/renderer/widgets/CreateWallet/model/flow-model.ts b/src/renderer/widgets/CreateWallet/model/flow-model.ts index 63a20c3c7..f6f3e8ae3 100644 --- a/src/renderer/widgets/CreateWallet/model/flow-model.ts +++ b/src/renderer/widgets/CreateWallet/model/flow-model.ts @@ -1,17 +1,16 @@ import { BN } from '@polkadot/util'; -import { combine, createEffect, createEvent, createStore, restore, sample } from 'effector'; +import { combine, createEvent, createStore, restore, sample } from 'effector'; import sortBy from 'lodash/sortBy'; import { delay, spread } from 'patronum'; import { type Account, AccountType, - type ChainId, ChainType, type Contact, CryptoType, type MultisigAccount, - type Signatory, + type NoID, SigningType, type Transaction, TransactionType, @@ -186,43 +185,6 @@ const $isEnoughBalance = combine( }, ); -type CreateWalletParams = { - name: string; - threshold: number; - signatories: Signatory[]; - chainId: ChainId | null; - isEthereumChain: boolean; -}; - -const createWalletFx = createEffect( - async ({ name, threshold, signatories, chainId, isEthereumChain }: CreateWalletParams) => { - const cryptoType = isEthereumChain ? CryptoType.ETHEREUM : CryptoType.SR25519; - const accountIds = signatories.map((s) => s.accountId); - const accountId = accountUtils.getMultisigAccountId(accountIds, threshold, cryptoType); - - walletModel.events.multisigCreated({ - wallet: { - name, - type: WalletType.MULTISIG, - signingType: SigningType.MULTISIG, - }, - accounts: [ - { - signatories, - chainId: chainId || undefined, - name: name.trim(), - accountId: accountId, - threshold: threshold, - creatorAccountId: accountId, - cryptoType: isEthereumChain ? CryptoType.ETHEREUM : CryptoType.SR25519, - chainType: isEthereumChain ? ChainType.ETHEREUM : ChainType.SUBSTRATE, - type: AccountType.MULTISIG, - }, - ], - }); - }, -); - const $fakeTx = combine( { chain: formModel.$createMultisigForm.fields.chain.$value, @@ -259,7 +221,7 @@ sample({ step: $step, }, filter: ({ step }, results) => { - return submitUtils.isSuccessResult(results[0].result) && isStep(Step.SUBMIT, step); + return isStep(Step.SUBMIT, step) && results.some(({ result }) => submitUtils.isSuccessResult(result)); }, fn: ({ signatories, chain, name, threshold }) => { const sortedSignatories = sortBy( @@ -267,26 +229,48 @@ sample({ 'accountId', ); - return { - name, - threshold, - chainId: chain.chainId, + const isEthereumChain = networkUtils.isEthereumBased(chain.options); + const cryptoType = isEthereumChain ? CryptoType.ETHEREUM : CryptoType.SR25519; + const accountIds = sortedSignatories.map((s) => s.accountId); + const accountId = accountUtils.getMultisigAccountId(accountIds, threshold, cryptoType); + + const account: Omit, 'walletId'> = { signatories: sortedSignatories, - isEthereumChain: networkUtils.isEthereumBased(chain.options), + chainId: chain.chainId, + name: name.trim(), + accountId: accountId, + threshold: threshold, + creatorAccountId: accountId, + cryptoType: isEthereumChain ? CryptoType.ETHEREUM : CryptoType.SR25519, + chainType: isEthereumChain ? ChainType.ETHEREUM : ChainType.SUBSTRATE, + type: AccountType.MULTISIG, + }; + + return { + wallet: { + name, + type: WalletType.MULTISIG, + signingType: SigningType.MULTISIG, + }, + accounts: [account], }; }, - target: createWalletFx, + target: walletModel.events.multisigCreated, }); sample({ - clock: createWalletFx.failData, - fn: (error) => error.message, + clock: walletModel.events.walletCreationFail, + filter: ({ params }) => params.wallet.type === WalletType.MULTISIG, + fn: ({ error }) => error.message, target: $error, }); sample({ - clock: createWalletFx.doneData, - target: walletProviderModel.events.completed, + clock: walletModel.events.walletCreatedDone, + filter: ({ wallet }) => wallet.type === WalletType.MULTISIG, + fn: ({ wallet }) => wallet.id, + // wallet selection shouldn't be here, but here we are + target: [walletModel.events.selectWallet, walletProviderModel.events.completed], }); // Submit