+
+
{#each tokens as t}
- -
- await select(t)}
- >{t.symbol.toUpperCase()}
-
+
{/each}
diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte
index 620fbc11d7a..1ad26931c71 100644
--- a/packages/bridge-ui/src/components/form/BridgeForm.svelte
+++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte
@@ -10,15 +10,35 @@
import { signer } from "../../store/signer";
import { BigNumber, ethers, Signer } from "ethers";
import { toast } from "@zerodevx/svelte-toast";
+ import ProcessingFee from "./ProcessingFee.svelte";
+ import { ETH } from "../../domain/token";
+ import SelectToken from "../buttons/SelectToken.svelte";
+
import type { Token } from "../../domain/token";
import type { BridgeType } from "../../domain/bridge";
import type { Chain } from "../../domain/chain";
+ import { truncateString } from "../../utils/truncateString";
+ import { pendingTransactions } from "../../store/transactions";
let amount: string;
let requiresAllowance: boolean = true;
let btnDisabled: boolean = true;
+ let tokenBalance: string;
+
+ $: getUserBalance($signer, $token);
+
+ async function getUserBalance(signer, token) {
+ if (signer && token) {
+ if (token.symbol == ETH.symbol) {
+ const userBalance = await signer.getBalance("latest");
+ tokenBalance = ethers.utils.formatEther(userBalance);
+ } else {
+ // TODO: read ERC20 balance from contract
+ }
+ }
+ }
- $: isBtnDisabled($signer, amount)
+ $: isBtnDisabled($signer, amount, $token, requiresAllowance)
.then((d) => (btnDisabled = d))
.catch((e) => console.log(e));
@@ -33,9 +53,7 @@
fromChain: Chain,
signer: Signer
) {
- if (!signer || !amt || !token || !fromChain) return true;
-
- return await $activeBridge.RequiresAllowance({
+ const allowance = await $activeBridge.RequiresAllowance({
amountInWei: amt
? ethers.utils.parseUnits(amt, token.decimals)
: BigNumber.from(0),
@@ -43,14 +61,20 @@
contractAddress: token.address,
spenderAddress: $chainIdToBridgeAddress.get(fromChain.id),
});
+ return allowance;
}
- async function isBtnDisabled(signer: Signer, amount: string) {
+ async function isBtnDisabled(
+ signer: Signer,
+ amount: string,
+ token: Token,
+ requiresAllowance: boolean
+ ) {
if (!signer) return true;
if (!amount) return true;
if (requiresAllowance) return true;
const balance = await signer.getBalance("latest");
- if (balance.lt(ethers.utils.parseUnits(amount, $token.decimals)))
+ if (balance.lt(ethers.utils.parseUnits(amount, token.decimals)))
return true;
return false;
@@ -69,9 +93,11 @@
});
console.log("approved, waiting for confirmations ", tx);
await $signer.provider.waitForTransaction(tx.hash, 3);
-
+ pendingTransactions.update((store) => {
+ store.push(tx);
+ return store;
+ });
requiresAllowance = false;
-
toast.push($_("toast.transactionSent"));
} catch (e) {
console.log(e);
@@ -94,59 +120,62 @@
memo: "memo",
});
- console.log("bridged", tx);
+ pendingTransactions.update((store) => {
+ store.push(tx);
+ return store;
+ });
+
toast.push($_("toast.transactionSent"));
} catch (e) {
console.log(e);
toast.push($_("toast.errorSendingTransaction"));
}
}
+
+ function useFullAmount() {
+ amount = tokenBalance;
+ }
+
+ function updateAmount(e: any) {
+ amount = (e.data as number).toString();
+ }
-