From e81b56105f35b2d39c9665bd2ec39c65443a99eb Mon Sep 17 00:00:00 2001 From: Sergey Zhuravlev Date: Tue, 12 Nov 2024 16:04:34 +0100 Subject: [PATCH 1/2] feat: add flexible multisig wallet and account types --- .../entities/wallet/lib/permission-utils.ts | 3 +++ .../entities/wallet/lib/wallet-utils.ts | 11 ++++++++++ .../entities/wallet/ui/Cards/WalletCardMd.tsx | 5 ++++- .../wallet/ui/WalletIcon/WalletIcon.tsx | 1 + .../emptyList/ui/EmptyAccountMessage.tsx | 1 + .../model/flexible-multisig-create.ts | 6 ++--- .../service/walletSelectService.ts | 2 ++ .../wallet-select/components/WalletGroup.tsx | 1 + .../__tests__/wallet-select-model.test.ts | 1 + .../service/walletSelectService.ts | 2 ++ .../flexibleMultisigBackground.svg | 13 +++++++++++ src/renderer/shared/core/index.ts | 2 ++ src/renderer/shared/core/types/account.ts | 22 ++++++++++++++++--- src/renderer/shared/core/types/wallet.ts | 9 ++++++++ src/renderer/shared/i18n/locales/en.json | 5 ++++- .../shared/ui/Icon/data/walletType.tsx | 4 ++++ .../widgets/CreateWallet/model/flow-model.ts | 5 ++--- .../CreateWallet/ui/CreateWalletProvider.tsx | 1 + 18 files changed, 83 insertions(+), 11 deletions(-) create mode 100644 src/renderer/shared/assets/images/walletTypes/flexibleMultisigBackground.svg diff --git a/src/renderer/entities/wallet/lib/permission-utils.ts b/src/renderer/entities/wallet/lib/permission-utils.ts index 5739ee19e..066c201c4 100644 --- a/src/renderer/entities/wallet/lib/permission-utils.ts +++ b/src/renderer/entities/wallet/lib/permission-utils.ts @@ -44,6 +44,7 @@ function canStake(wallet: Wallet): boolean { function canCreateMultisigTx(wallet: Wallet): boolean { if (walletUtils.isWatchOnly(wallet)) return false; if (walletUtils.isMultisig(wallet)) return false; + if (walletUtils.isFlexibleMultisig(wallet)) return false; if (walletUtils.isProxied(wallet)) { const isAnyProxy = accountUtils.isAnyProxyType(wallet.accounts[0]); const isNonTransfer = accountUtils.isNonTransferProxyType(wallet.accounts[0]); @@ -56,6 +57,7 @@ function canCreateMultisigTx(wallet: Wallet): boolean { function canApproveMultisigTx(wallet: Wallet): boolean { if (walletUtils.isWatchOnly(wallet)) return false; if (walletUtils.isMultisig(wallet)) return false; + if (walletUtils.isFlexibleMultisig(wallet)) return false; if (walletUtils.isProxied(wallet)) { return false; @@ -72,6 +74,7 @@ function canApproveMultisigTx(wallet: Wallet): boolean { function canRejectMultisigTx(wallet: Wallet): boolean { if (walletUtils.isWatchOnly(wallet)) return false; if (walletUtils.isMultisig(wallet)) return false; + if (walletUtils.isFlexibleMultisig(wallet)) return false; if (walletUtils.isProxied(wallet)) { return false; diff --git a/src/renderer/entities/wallet/lib/wallet-utils.ts b/src/renderer/entities/wallet/lib/wallet-utils.ts index a83f821d3..c1137a372 100644 --- a/src/renderer/entities/wallet/lib/wallet-utils.ts +++ b/src/renderer/entities/wallet/lib/wallet-utils.ts @@ -1,5 +1,6 @@ import { type Account, + type FlexibleMultisigWallet, type ID, type MultiShardWallet, type MultisigWallet, @@ -20,6 +21,7 @@ export const walletUtils = { isMultiShard, isSingleShard, isMultisig, + isFlexibleMultisig, isWatchOnly, isNovaWallet, isWalletConnect, @@ -33,6 +35,7 @@ export const walletUtils = { getAccountBy, getAccountsBy, + getAllAccounts, getWalletFilteredAccounts, getWalletsFilteredAccounts, }; @@ -55,6 +58,10 @@ function isMultisig(wallet?: Wallet): wallet is MultisigWallet { return wallet?.type === WalletType.MULTISIG; } +function isFlexibleMultisig(wallet?: Wallet): wallet is FlexibleMultisigWallet { + return wallet?.type === WalletType.FLEXIBLE_MULTISIG; +} + function isWatchOnly(wallet?: Wallet): wallet is WatchOnlyWallet { return wallet?.type === WalletType.WATCH_ONLY; } @@ -111,6 +118,10 @@ function getAccountsBy(wallets: Wallet[], accountFn: (account: Account, wallet: }, []); } +function getAllAccounts(wallets: Wallet[]): Account[] { + return wallets.reduce((acc, wallet) => acc.concat(wallet.accounts), []); +} + function getAccountBy(wallets: Wallet[], accountFn: (account: Account, wallet: Wallet) => boolean): Account | null { for (const wallet of wallets) { const account = wallet.accounts.find((account) => accountFn(account, wallet)); diff --git a/src/renderer/entities/wallet/ui/Cards/WalletCardMd.tsx b/src/renderer/entities/wallet/ui/Cards/WalletCardMd.tsx index 78cb5c8dd..a1d2d0dae 100644 --- a/src/renderer/entities/wallet/ui/Cards/WalletCardMd.tsx +++ b/src/renderer/entities/wallet/ui/Cards/WalletCardMd.tsx @@ -36,7 +36,10 @@ export const WalletCardMd = ({ wallet, description, prefix, hideIcon, className, className, )} > -