Skip to content

Commit

Permalink
Refactor code and support HydraDX
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJay1024 committed Jun 19, 2024
1 parent a83db9c commit 93aeefc
Show file tree
Hide file tree
Showing 38 changed files with 986 additions and 420 deletions.
13 changes: 13 additions & 0 deletions public/images/asset/hdx.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/asset/ring.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions public/images/network/hydration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/wallet/evm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions src/components/balance-input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ export default function BalanceInput({
}, [balance, asset, placeholder]);

const min = useMemo(() => {
if (cross && cross.fee.asset.native) {
if (cross && cross.fee.asset.local.id === asset.id) {
return cross.fee.amount;
}
return undefined;
}, [cross]);
}, [cross, asset.id]);

const handleInputChange = useCallback<ChangeEventHandler<HTMLInputElement>>(
(e) => {
Expand Down Expand Up @@ -133,12 +133,14 @@ export default function BalanceInput({
text={`* Limit: ${formatBalance(assetLimit ?? BN_ZERO, asset?.decimals ?? 0)}, supply: ${formatBalance(
(assetSupply ?? BN_ZERO).add(value?.amount ?? BN_ZERO),
asset?.decimals ?? 0,
)}`}
)}.`}
/>
) : requireMin ? (
<InputAlert text={`* At least ${formatBalance(min ?? BN_ZERO, asset?.decimals ?? 0)} for tx fee`} />
<InputAlert
text={`* At least ${formatBalance(min ?? BN_ZERO, asset?.decimals ?? 0)} ${asset.symbol} for tx fee.`}
/>
) : insufficient ? (
<InputAlert text="* Insufficient" />
<InputAlert text="* Insufficient." />
) : null}

{/* Invisible */}
Expand Down
24 changes: 13 additions & 11 deletions src/components/connect-wallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,21 @@ export default function ConnectWallet({ who, kind = "component", height = "paddi
[clearValue, setActiveWallet, setActiveAccount],
);

const [supportedRainbow, supportedTalisman] = useMemo(() => {
return [supported.some((id) => id === WalletID.RAINBOW), supported.some((id) => id === WalletID.TALISMAN)];
const [supportedWalletEvm, supportedWalletTalisman] = useMemo(() => {
return [supported.some((id) => id === WalletID.EVM), supported.some((id) => id === WalletID.TALISMAN)];
}, [supported]);

useEffect(() => {
if (!supported.some((id) => id === WalletID.TALISMAN) && activeWallet === WalletID.TALISMAN) {
setActiveWallet(undefined);
clearValue(undefined);
} else if (!supported.some((id) => id === WalletID.RAINBOW) && activeWallet === WalletID.RAINBOW) {
} else if (!supported.some((id) => id === WalletID.EVM) && activeWallet === WalletID.EVM) {
setActiveWallet(undefined);
clearValue(undefined);
}
}, [supported, activeWallet, clearValue, setActiveWallet]);

const walletIcon = kind === "primary" ? null : activeWallet === WalletID.RAINBOW ? "rainbow.svg" : "talisman-red.svg";
const walletIcon = kind === "primary" ? null : activeWallet === WalletID.EVM ? "evm.png" : "talisman-red.svg";

// Major for page header
if (kind === "primary" && sender?.address) {
Expand All @@ -105,7 +105,9 @@ export default function ConnectWallet({ who, kind = "component", height = "paddi

return (talismanAccounts.length || activeAddress) && activeWallet ? (
<Button onClick={handleDisconnect} kind={kind} height={height}>
{walletIcon && <Image width={16} height={16} alt="Wallet" src={`/images/wallet/${walletIcon}`} />}
{walletIcon && (
<Image width={16} height={16} alt="Wallet" src={`/images/wallet/${walletIcon}`} className="rounded-full" />
)}
<span>Disconnect</span>
</Button>
) : (
Expand All @@ -129,18 +131,18 @@ export default function ConnectWallet({ who, kind = "component", height = "paddi
connectTalisman();
setIsOpenFalse();
}}
disabled={!supportedTalisman}
disabled={!supportedWalletTalisman}
/>
<Item
who={who}
icon="rainbow.svg"
name="Rainbow"
icon="evm.png"
name="EVM wallets"
onClick={() => {
setActiveWallet(WalletID.RAINBOW);
setActiveWallet(WalletID.EVM);
openConnectModal?.();
setIsOpenFalse();
}}
disabled={!supportedRainbow}
disabled={!supportedWalletEvm}
/>
</div>
</Modal>
Expand Down Expand Up @@ -195,7 +197,7 @@ function Item({
disabled={disabled}
onClick={onClick}
>
<Image width={20} height={20} alt="Wallet icon" src={`/images/wallet/${icon}`} />
<Image width={20} height={20} alt="Wallet icon" src={`/images/wallet/${icon}`} className="rounded-full" />
<span>{name}</span>
</button>
</Tooltip>
Expand Down
Loading

0 comments on commit 93aeefc

Please sign in to comment.