Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bridge-ui): Chain block #13452

Merged
merged 2 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/bridge-ui/src/components/Transaction.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
}

// confirm after switch chain that it worked.
if (!isOnCorrectChain($signer, bridgeTx.toChainId)) {
if (!(await isOnCorrectChain($signer, bridgeTx.toChainId))) {
errorToast('You are connected to the wrong chain in your wallet');
return;
}
Expand Down Expand Up @@ -128,7 +128,7 @@
}

// confirm after switch chain that it worked.
if (!isOnCorrectChain($signer, bridgeTx.fromChainId)) {
if (!(await isOnCorrectChain($signer, bridgeTx.fromChainId))) {
errorToast('You are connected to the wrong chain in your wallet');
return;
}
Expand Down
19 changes: 13 additions & 6 deletions packages/bridge-ui/src/components/form/BridgeForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,24 @@
return allowance;
}

function isBtnDisabled(
async function isBtnDisabled(
signer: Signer,
amount: string,
token: Token,
tokenBalance: string,
requiresAllowance: boolean,
memoError: string,
fromChain: Chain,
) {
if (!signer) return true;
if (!tokenBalance) return true;

const chainId = $fromChain.id;
if (!fromChain) return true;
const chainId = fromChain.id;

if (!chainId || !chains[chainId.toString()]) return true;

if (!(await isOnCorrectChain(signer, fromChain.id))) return true;

if (!amount || ethers.utils.parseUnits(amount).eq(BigNumber.from(0)))
return true;
if (isNaN(parseFloat(amount))) return true;
Expand Down Expand Up @@ -218,7 +222,7 @@
throw Error('Invalid custom recipient address');
}

if (!isOnCorrectChain($signer, $fromChain.id)) {
if (!(await isOnCorrectChain($signer, $fromChain.id))) {
errorToast('You are connected to the wrong chain in your wallet');
return;
}
Expand Down Expand Up @@ -373,14 +377,17 @@

$: getUserBalance($signer, $token, $fromChain);

$: btnDisabled = isBtnDisabled(
$: isBtnDisabled(
$signer,
amount,
$token,
tokenBalance,
requiresAllowance,
memoError,
);
$fromChain,
)
.then((d) => (btnDisabled = d))
.catch((e) => console.error(e));

$: checkAllowance(amount, $token, $bridgeType, $fromChain, $signer)
.then((a) => (requiresAllowance = a))
Expand Down