Skip to content

Commit

Permalink
chore: add multisig account not found hint
Browse files Browse the repository at this point in the history
  • Loading branch information
vzxh committed Mar 9, 2022
1 parent 53cc3da commit 29f42ec
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,6 @@
},
"network not supported": "This network is not currently supported",
"remark": "Remark",
"endpoint": "Endpoint"
"endpoint": "Endpoint",
"multisig account not exist": "Multisig account not found, please create it first"
}
3 changes: 2 additions & 1 deletion public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,6 @@
},
"network not supported": "暂不支持该网络",
"remark": "备注",
"endpoint": "节点"
"endpoint": "节点",
"multisig account not exist": "未找到本地的多签账号配置"
}
2 changes: 1 addition & 1 deletion src/components/WalletForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export function WalletForm() {

updateMultiAccountScope(values, network);
message.success(t('success'));
history.push('/');
history.push('/' + history.location.hash);
} catch (error: unknown) {
if (error instanceof Error) {
message.error(t(error.message));
Expand Down
2 changes: 1 addition & 1 deletion src/components/WalletState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export function WalletState() {
try {
keyring.forgetAccount(multisigAccount?.address as string);
message.success(t('success'));
history.push('/');
history.push('/' + history.location.hash);
} catch (error: unknown) {
if (error instanceof Error) {
message.error(error.message);
Expand Down
34 changes: 26 additions & 8 deletions src/pages/Extrinsic.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
import { encodeAddress } from '@polkadot/util-crypto';
import keyring from '@polkadot/ui-keyring';
import { KeyringAddress } from '@polkadot/ui-keyring/types';
import { Card, Spin } from 'antd';
import { Card, message, Spin } from 'antd';
import { useManualQuery } from 'graphql-hooks';
import { useEffect, useState } from 'react';
import { useParams } from 'react-router-dom';
import { useEffect, useMemo, useState } from 'react';
import { useParams, useHistory } from 'react-router-dom';
import { MULTISIG_ACCOUNT_DETAIL_QUERY } from 'src/config';
import { ShareScope } from 'src/model';
import { updateMultiAccountScope } from 'src/utils';
import { isCustomRpc, updateMultiAccountScope } from 'src/utils';
import { useTranslation } from 'react-i18next';
import { ExtrinsicRecords } from '../components/ExtrinsicRecords';
import { WalletState } from '../components/WalletState';
import { useApi } from '../hooks';
import { EntriesProvider } from '../providers/multisig-provider';

export function Extrinsic() {
const { api, network, chain } = useApi();
const history = useHistory();
const { t } = useTranslation();
const { api, network, chain, rpc } = useApi();
const { account } = useParams<{ account: string }>();
const ss58Account = encodeAddress(account, Number(chain.ss58Format));
const [multisig, setMultisig] = useState<KeyringAddress | undefined>();

const { isCustomNetwork } = useMemo(() => {
return {
isCustomNetwork: isCustomRpc(rpc),
};
}, [rpc]);

const [fetchMultisigDetail, { data: multisigDetail }] = useManualQuery<{
multisigAccount: { id: string; threshold: number; members: string[] };
}>(MULTISIG_ACCOUNT_DETAIL_QUERY, {
Expand All @@ -30,12 +39,18 @@ export function Extrinsic() {
const localMultisig = keyring.getAccount(ss58Account);

if (!localMultisig) {
fetchMultisigDetail({ variables: { account: ss58Account }, skipCache: true });
if (isCustomNetwork) {
message.warn(t('multisig account not exist'));
history.push('/' + history.location.hash);
} else {
fetchMultisigDetail({ variables: { account: ss58Account }, skipCache: true });
}
} else {
setMultisig(keyring.getAccount(ss58Account));
}
}, [ss58Account, fetchMultisigDetail]);
}, [isCustomNetwork, ss58Account, fetchMultisigDetail, history, t]);

// eslint-disable-next-line complexity
useEffect(() => {
const localMultisig = keyring.getAccount(ss58Account);

Expand Down Expand Up @@ -68,8 +83,11 @@ export function Extrinsic() {
);

setMultisig(keyring.getAccount(ss58Account));
} else if (!localMultisig && multisigDetail && multisigDetail.multisigAccount === null) {
message.warn(t('multisig account not exist'));
history.push('/' + history.location.hash);
}
}, [ss58Account, multisigDetail, api, network]);
}, [ss58Account, multisigDetail, api, network, history, t]);

if (!multisig) {
return (
Expand Down

0 comments on commit 29f42ec

Please sign in to comment.