Skip to content

Commit

Permalink
Feat: removed multishard wallets from signatory options (#1102)
Browse files Browse the repository at this point in the history
* feat: removed multishrd wallets from signatory options

* chore: pr comments fix

---------

Co-authored-by: Egor B <[email protected]>
  • Loading branch information
egor0798 and Egor B authored Oct 9, 2023
1 parent 96fbb85 commit fd7477e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
11 changes: 7 additions & 4 deletions src/renderer/entities/account/model/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { u8aToHex } from '@polkadot/util';

import { AccountDS, ID } from '@renderer/shared/api/storage';
import {
ChainId,
CryptoType,
AccountId,
ChainId,
ChainType,
CryptoType,
SigningType,
Threshold,
WalletType,
} from '../../../domain/shared-kernel';
import { Signatory } from '@renderer/entities/signatory/model/signatory';
import { Wallet } from '@renderer/entities/wallet';

export type Account = {
walletId?: ID;
Expand Down Expand Up @@ -112,10 +113,12 @@ export const isMultishard = (account?: Account | MultisigAccount): boolean => {
return Boolean(account.walletId);
};

export function isWalletContact(account?: Account | MultisigAccount): boolean {
export function isWalletContact(account?: Account | MultisigAccount, wallet?: Wallet): boolean {
if (!account) return false;
const isMultishard = wallet && wallet.type === WalletType.MULTISHARD_PARITY_SIGNER;
const isWatchOnly = account.signingType === SigningType.WATCH_ONLY;

return account.signingType !== SigningType.WATCH_ONLY && !isMultisig(account);
return !isWatchOnly && !isMultishard && !isMultisig(account);
}

export function isVaultAccount(account?: Account | MultisigAccount): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export const MultisigAccount = ({ isOpen, onClose, onComplete }: Props) => {
<WalletForm
isActive={activeStep === Step.INIT}
accounts={accounts}
wallets={wallets}
signatories={signatories}
isLoading={isLoading}
onGoBack={goToPrevStep}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const SelectSignatories = ({ isActive, wallets, accounts, contacts, onSel
.map((contact, index) => ({ ...contact, index: index.toString() }));

const walletContacts = accounts.reduce<ExtendedWallet[]>((acc, a, index) => {
if (isWalletContact(a)) {
if (isWalletContact(a, walletMap[a.walletId || ''])) {
acc.push({
index: index.toString(),
name: a.name || a.accountId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Controller, useForm, SubmitHandler } from 'react-hook-form';
import { keyBy } from 'lodash';

import { Alert, Button, Input, InputHint, Select, SmallTitleText } from '@renderer/shared/ui';
import { useI18n, useMatrix } from '@renderer/app/providers';
Expand All @@ -12,6 +13,7 @@ import {
MultisigAccount,
} from '@renderer/entities/account';
import { SigningType, AccountId } from '@renderer/domain/shared-kernel';
import { WalletDS } from '@renderer/shared/api/storage';

type MultisigAccountForm = {
name: string;
Expand All @@ -31,6 +33,7 @@ const getThresholdOptions = (optionsAmount: number): DropdownOption<number>[] =>
type Props = {
signatories: Signatory[];
accounts: (Account | MultisigAccount)[];
wallets: WalletDS[];
isActive: boolean;
isLoading: boolean;
onContinue: () => void;
Expand All @@ -41,6 +44,7 @@ type Props = {
export const WalletForm = ({
signatories,
accounts,
wallets,
onContinue,
isActive,
isLoading,
Expand All @@ -66,6 +70,8 @@ export const WalletForm = ({
const threshold = watch('threshold');
const thresholdOptions = getThresholdOptions(signatories.length - 1);

const walletMap = keyBy(wallets, 'id');

const multisigAccountId =
threshold &&
getMultisigAccountId(
Expand All @@ -81,7 +87,7 @@ export const WalletForm = ({
onCreateAccount(name, threshold.value, creator.accountId);
};

const hasNoAccounts = accounts.filter(isWalletContact).length === 0;
const hasNoAccounts = accounts.filter((a) => isWalletContact(a, walletMap[a.walletId || ''])).length === 0;
const hasOwnSignatory = signatories.some((s) =>
accounts.find((a) => a.accountId === s.accountId && a.signingType !== SigningType.WATCH_ONLY && !isMultisig(a)),
);
Expand Down

0 comments on commit fd7477e

Please sign in to comment.