Skip to content

Commit

Permalink
feat: query multisig account from subql (#140)
Browse files Browse the repository at this point in the history
* feat: query multisig account from subql

* fix: fix subql variable name

* chore: add multisig account not found hint

* chore: update multisig account not found hint

* feat: add explorer config in custom network

* chore: add unavailable endpoint hint content
  • Loading branch information
vzxh authored Mar 10, 2022
1 parent 306572c commit 3934284
Show file tree
Hide file tree
Showing 15 changed files with 617 additions and 327 deletions.
11 changes: 9 additions & 2 deletions public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"pending": "Pending"
},
"save": "Save",
"add": "Add",
"submit": "Submit",
"submit the following extrinsic": "submit the following extrinsic",
"submit_extrinsic": "Initiate Extrinsic",
Expand Down Expand Up @@ -180,6 +181,12 @@
"add custom network success": "Add custom network success"
},
"network not supported": "This network is not currently supported",
"remark": "Remark",
"endpoint": "Endpoint"
"remark": "Remark Name*",
"endpoint": "Endpoint*",
"multisig account not exist": "Multi-signature account “{{account}}” Not found in current network",
"explorer optional": "Explorer (optional)",
"mainnet": "Mainnet",
"testnet": "Testnet",
"custom network": "Custom Network",
"unavailable endpoint": "Unavailable Endpoint"
}
11 changes: 9 additions & 2 deletions public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
"pending": "等待批准"
},
"save": "保存",
"add": "添加",
"submit": "提交",
"submit the following extrinsic": "提交下面的外部信息",
"submit_extrinsic": "发起交易",
Expand Down Expand Up @@ -178,6 +179,12 @@
"add custom network success": "保存成功"
},
"network not supported": "暂不支持该网络",
"remark": "备注",
"endpoint": "节点"
"remark": "备注*",
"endpoint": "节点*",
"multisig account not exist": "未在当前网络找到多签账号:“{{account}}”",
"explorer optional": "浏览器 (可选)",
"mainnet": "主网",
"testnet": "测试网",
"custom network": "自定义网络",
"unavailable endpoint": "无效的节点"
}
26 changes: 22 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ import { Path, routes } from './config/routes';
import { useApi } from './hooks';
import { Network } from './model';
import { Connecting } from './pages/Connecting';
import { isCustomRpc } from './utils';

const genHeaderLinkStyle = (classes: TemplateStringsArray, network: Network) => {
return `text-white opacity-80 hover:opacity-100 leading-normal whitespace-nowrap cursor-pointer transition-all duration-200 mr-4 dark:text-${network}-main ${classes.join(
' '
)}`;
};

// eslint-disable-next-line complexity
function App() {
const { t } = useTranslation();
const history = useHistory();
const { networkStatus, network, networkConfig } = useApi();
const { networkStatus, network, networkConfig, rpc } = useApi();
const { systemChain, systemName, specName, isDevelopment, apiError } = usePolkaApi();
const polkaLogo = useMemo(
() => (networkStatus === 'success' ? '/image/polka-check.png' : '/image/polka-cross.png'),
Expand All @@ -46,8 +48,22 @@ function App() {
return Object.keys(NETWORK_CONFIG).indexOf(network) >= 0 ? network : 'custom';
}, [network]);

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

const [selectNetworkModalVisible, setSelectNetworkModalVisible] = useState(false);

const openExplorer = () => {
if (isCustomNetwork) {
window.open(`https://${networkConfig?.explorerHostName}.subscan.io`, '_blank');
} else {
window.open(`https://${network}.subscan.io`, '_blank');
}
};

return (
<>
<GlobalStyle uiHighlight={uiHighlight} />
Expand All @@ -68,9 +84,11 @@ function App() {
</span>

<div className="flex items-center justify-between">
<span onClick={() => window.open(`https://${network}.subscan.io`, '_blank')} className={headerLinkStyle}>
{t('explorer')}
</span>
{(!isCustomNetwork || networkConfig?.explorerHostName) && (
<span onClick={openExplorer} className={headerLinkStyle}>
{t('explorer')}
</span>
)}

<HeadAccounts />

Expand Down
76 changes: 65 additions & 11 deletions src/components/SubscanLink.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Typography } from 'antd';
import { CSSProperties, PropsWithChildren, useMemo } from 'react';
import { CopyOutlined } from '@ant-design/icons';
import { getThemeVar } from '../utils';
import { getThemeVar, isCustomRpc } from '../utils';
import { useApi } from '../hooks';

const { Link } = Typography;
const { Text } = Typography;

export interface SubscanLinkProps extends PropsWithChildren<unknown> {
address?: string;
Expand All @@ -15,8 +15,9 @@ export interface SubscanLinkProps extends PropsWithChildren<unknown> {
copyable?: boolean;
}

// eslint-disable-next-line complexity
export function SubscanLink({ address, extrinsic, children, copyable, block, ...other }: SubscanLinkProps) {
const { network } = useApi();
const { network, rpc, networkConfig } = useApi();

const mainColor = useMemo(() => {
return getThemeVar(network, '@project-main-bg');
Expand All @@ -26,11 +27,31 @@ export function SubscanLink({ address, extrinsic, children, copyable, block, ...
return getThemeVar(network, '@link-color');
}, [network]);

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

const openLink = (url: string) => {
if (!url) {
return;
}
window.open(url, '_blank');
};

if (address) {
return (
<Link
href={`https://${network}.subscan.io/account/${address}`}
target="_blank"
<Text
onClick={() =>
openLink(
!isCustomNetwork
? `https://${network}.subscan.io/account/${address}`
: networkConfig?.explorerHostName
? `https://${networkConfig?.explorerHostName}.subscan.io/account/${address}`
: ''
)
}
copyable={
copyable && {
tooltips: false,
Expand All @@ -50,28 +71,61 @@ export function SubscanLink({ address, extrinsic, children, copyable, block, ...
style={{
color: linkColor,
height: '20px',
cursor: !isCustomNetwork || networkConfig?.explorerHostName ? 'pointer' : 'default',
}}
>
{address}
</Link>
</Text>
);
}

if (extrinsic) {
const { height, index } = extrinsic;

return (
<Link href={`https://${network}.subscan.io/extrinsic/${height}-${index}`} target="_blank" {...other}>
<Text
{...other}
onClick={() => {
openLink(
!isCustomNetwork
? `https://${network}.subscan.io/extrinsic/${height}-${index}`
: networkConfig?.explorerHostName
? `https://${networkConfig?.explorerHostName}.subscan.io/extrinsic/${height}-${index}`
: ''
);
}}
style={{
color: linkColor,
height: '20px',
cursor: !isCustomNetwork || networkConfig?.explorerHostName ? 'pointer' : 'default',
}}
>
{children}
</Link>
</Text>
);
}

if (block) {
return (
<Link href={`https://${network}.subscan.io/block/${block}`} target="_blank" {...other}>
<Text
{...other}
onClick={() => {
openLink(
!isCustomNetwork
? `https://${network}.subscan.io/block/${block}`
: networkConfig?.explorerHostName
? `https://${networkConfig?.explorerHostName}.subscan.io/block/${block}`
: ''
);
}}
style={{
color: linkColor,
height: '20px',
cursor: !isCustomNetwork || networkConfig?.explorerHostName ? 'pointer' : 'default',
}}
>
{block}
</Link>
</Text>
);
}

Expand Down
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
Loading

0 comments on commit 3934284

Please sign in to comment.