Skip to content

Commit

Permalink
chore: Optimize if-else statements (#715)
Browse files Browse the repository at this point in the history
* chore: Optimize if else statements

* chore: update changeset

* chore: update changeset
  • Loading branch information
LuciferHuang committed Mar 27, 2024
1 parent afc22c9 commit f4f80a7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 46 deletions.
7 changes: 7 additions & 0 deletions .changeset/small-eyes-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ant-design/web3-solana": patch
"@ant-design/web3-wagmi": patch
"@ant-design/web3": patch
---

chore: Optimize if-else statements
4 changes: 2 additions & 2 deletions .dumi/theme/builtins/IconSearch/CopyableIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ const CopyableIcon: React.FC<CopyableIconProps> = ({
const onCopy = (text: string, result: boolean) => {
if (result) {
onCopied(name, text);
} else {
message.error('Copy icon name failed, please try again.');
return;
}
message.error('Copy icon name failed, please try again.');
};

return (
Expand Down
9 changes: 4 additions & 5 deletions packages/solana/src/solana-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,11 @@ export const AntDesignWeb3ConfigProvider: React.FC<
name: c.name,
icon: c.icon,
};
} else {
console.error(
`Can not find chain ${item.id}, SolanaWeb3ConfigProvider only support Solana`,
);
return null;
}
console.error(
`Can not find chain ${item.id}, SolanaWeb3ConfigProvider only support Solana`,
);
return null;
})
.filter((item) => item !== null) as (Chain & SolanaChainConfig)[];
}, [props.availableChains, props.chainAssets]);
Expand Down
17 changes: 8 additions & 9 deletions packages/wagmi/src/wagmi-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,11 @@ export const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderPr
name: c.name,
icon: c.icon,
};
} else {
console.error(
`Can not find chain ${item.id}, you should config it in WagmiWeb3ConfigProvider 'chains'.`,
);
return null;
}
console.error(
`Can not find chain ${item.id}, you should config it in WagmiWeb3ConfigProvider 'chains'.`,
);
return null;
})
.filter((item) => item !== null) as Chain[];
}, [availableChains, chainAssets]);
Expand Down Expand Up @@ -223,11 +222,11 @@ export const AntDesignWeb3ConfigProvider: React.FC<AntDesignWeb3ConfigProviderPr
if (!chain) {
// hava not connected any chain
setCurrentChain(c);
} else {
switchChain?.({
chainId: c.id,
});
return;
}
switchChain?.({
chainId: c.id,
});
}}
getNFTMetadata={async ({ address: contractAddress, tokenId }) =>
getNFTMetadata(config, contractAddress, tokenId, chain?.id)
Expand Down
12 changes: 6 additions & 6 deletions packages/web3/src/connect-modal/components/MainPanelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ const MainPanelHeader: React.FC<MainPanelHeaderProps> = (props) => {
const { prefixCls, panelRouteBack, canBack } = useContext(connectModalContext);

const handleBack = async () => {
if (onBack) {
const isBack = await onBack();
if (isBack !== false) {
panelRouteBack();
}
} else {
if (!onBack) {
panelRouteBack();
return;
}
const isBack = await onBack();
if (isBack !== false) {
panelRouteBack();
}
};
Expand Down
42 changes: 21 additions & 21 deletions packages/web3/src/connector/connector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,29 @@ export const Connector: React.FC<ConnectorProps> = (props) => {
{React.cloneElement(children as React.ReactElement<ConnectorTriggerProps>, {
account,
onConnectClick: async (wallet?: Wallet) => {
if (wallet) {
if (await wallet?.hasExtensionInstalled?.()) {
// call extension directly
connectWallet(wallet, {
connectType: 'extension',
});
} else {
// show qr code
if (actionRef.current?.selectWallet) {
// ConnectModal already mounted, call select
actionRef.current.selectWallet(wallet);
} else {
// ConnectModal not mounted, set defaultSelectWallet
connectWallet(wallet, {
connectType: 'qrCode',
});
setDefaultSelectedWallet(wallet);
}
setOpen(true);
}
} else {
if (!wallet) {
setOpen(true);
return;
}
if (await wallet?.hasExtensionInstalled?.()) {
// call extension directly
connectWallet(wallet, {
connectType: 'extension',
});
return;
}
// show qr code
if (actionRef.current?.selectWallet) {
// ConnectModal already mounted, call select
actionRef.current.selectWallet(wallet);
} else {
// ConnectModal not mounted, set defaultSelectWallet
connectWallet(wallet, {
connectType: 'qrCode',
});
setDefaultSelectedWallet(wallet);
}
setOpen(true);
},
onDisconnectClick: () => {
setLoading(true);
Expand Down
6 changes: 3 additions & 3 deletions packages/web3/src/hooks/demos/useConnection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const Demo: React.FC = () => {
onClick={() => {
if (account) {
disconnect?.();
} else {
console.log('connect');
connect?.();
return;
}
console.log('connect');
connect?.();
}}
>
{account ? 'Disconnect' : 'Connect'}
Expand Down

0 comments on commit f4f80a7

Please sign in to comment.