Skip to content

Commit

Permalink
fix: multisig wallet select should work fine now (i hope)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthecat committed Nov 18, 2024
1 parent 21156d4 commit f7fad9d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/renderer/entities/wallet/model/wallet-model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { combine, createEffect, createEvent, createStore, sample } from 'effector';
import { type UnitValue, combine, createEffect, createEvent, createStore, sample } from 'effector';
import groupBy from 'lodash/groupBy';
import { combineEvents, readonly } from 'patronum';

Expand All @@ -23,6 +23,9 @@ type DbWallet = Omit<Wallet, 'accounts'>;
type CreateParams<T extends Account = Account> = {
wallet: Omit<NoID<Wallet>, 'isActive' | 'accounts'>;
accounts: Omit<NoID<T>, 'walletId'>[];
// external means wallet was created by someone else and discovered later
// TODO this flag is related to multisig creation and should disappear after wallet feature decomposition
external: boolean;
};

const walletStarted = createEvent();
Expand Down Expand Up @@ -85,6 +88,7 @@ const fetchAllWalletsFx = createEffect(async (): Promise<DbWallet[]> => {
type CreateResult = {
wallet: DbWallet;
accounts: Account[];
external: boolean;
};
const walletCreatedFx = createEffect(async ({ wallet, accounts }: CreateParams): Promise<CreateResult | undefined> => {
const dbWallet = await storageService.wallets.create({ ...wallet, isActive: false });
Expand All @@ -96,14 +100,15 @@ const walletCreatedFx = createEffect(async ({ wallet, accounts }: CreateParams):

if (!dbAccounts) return undefined;

return { wallet: dbWallet, accounts: dbAccounts };
return { wallet: dbWallet, accounts: dbAccounts, external: false };
});

const multishardCreatedFx = createEffect(
async ({
wallet,
accounts,
}: CreateParams<BaseAccount | ChainAccount | ShardAccount>): Promise<CreateResult | undefined> => {
external,
}: UnitValue<typeof multishardCreated>): Promise<(CreateResult & { external: boolean }) | undefined> => {
const dbWallet = await storageService.wallets.create({ ...wallet, isActive: false });

if (!dbWallet) return undefined;
Expand Down Expand Up @@ -148,7 +153,7 @@ const multishardCreatedFx = createEffect(
multishardAccounts.push(...dbChainAccounts);
}

return { wallet: dbWallet, accounts: multishardAccounts };
return { wallet: dbWallet, accounts: multishardAccounts, external };
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ sample({
sample({
clock: walletModel.events.walletCreatedDone,
source: walletModel.$wallets,
filter: (wallets, { wallet }) => {
filter: (wallets, { wallet, external }) => {
const foundWallet = wallets.find((w) => w.id === wallet.id);
if (!foundWallet) return false;

return !walletUtils.isProxied(foundWallet) && !walletUtils.isMultisig(foundWallet);
return !walletUtils.isProxied(foundWallet) && !walletUtils.isMultisig(foundWallet) && !external;
},
fn: (_, { wallet }) => wallet.id,
target: walletModel.events.selectWallet,
Expand Down
6 changes: 5 additions & 1 deletion src/renderer/processes/multisigs/model/multisigs-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { multisigUtils } from '../lib/mulitisigs-utils';
type SaveMultisigParams = {
wallet: Omit<NoID<Wallet>, 'isActive' | 'accounts'>;
accounts: Omit<NoID<MultisigAccount>, 'walletId'>[];
external: boolean;
};

const MULTISIG_DISCOVERY_TIMEOUT = 30000;
Expand Down Expand Up @@ -134,7 +135,10 @@ sample({
fn: ({ indexedMultisigs, chain }) => {
return indexedMultisigs.map(
({ threshold, accountId, signatories }) =>
multisigUtils.buildMultisig({ threshold, accountId, signatories, chain }) as SaveMultisigParams,
({
...multisigUtils.buildMultisig({ threshold, accountId, signatories, chain }),
external: true,
}) as SaveMultisigParams,
);
},
target: saveMultisigFx,
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/widgets/CreateWallet/model/flow-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ sample({
signingType: SigningType.MULTISIG,
},
accounts: [account],
external: false,
};
},
target: walletModel.events.multisigCreated,
Expand All @@ -265,7 +266,7 @@ sample({

sample({
clock: walletModel.events.walletCreatedDone,
filter: ({ wallet }) => wallet.type === WalletType.MULTISIG,
filter: ({ wallet, external }) => wallet.type === WalletType.MULTISIG && !external,
fn: ({ wallet }) => wallet.id,
// wallet selection shouldn't be here, but here we are
target: [walletModel.events.selectWallet, walletProviderModel.events.completed],
Expand Down

0 comments on commit f7fad9d

Please sign in to comment.