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

feat(bridge-ui-v2): Processing Fee #14170

Merged
merged 75 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
25b2902
wip
jscriptcoder Jul 10, 2023
d55c7ba
wip: faucet
jscriptcoder Jul 10, 2023
b64b0a2
wip: Modal
jscriptcoder Jul 11, 2023
2d1f1d2
wip
jscriptcoder Jul 11, 2023
bd2e4a7
wip
jscriptcoder Jul 11, 2023
2fd98ee
wip
jscriptcoder Jul 11, 2023
1ed70be
wip
jscriptcoder Jul 11, 2023
397a40b
Faucet
jscriptcoder Jul 11, 2023
2c00949
Merge branch 'main' into mint_test_tokens
jscriptcoder Jul 11, 2023
93166b7
minor change
jscriptcoder Jul 12, 2023
5b9cdb9
Merge branch 'mint_test_tokens' of https://github.com/taikoxyz/taiko-…
jscriptcoder Jul 12, 2023
8275a4b
Merge branch 'main' into mint_test_tokens
jscriptcoder Jul 12, 2023
1773ec5
wip: mobile
jscriptcoder Jul 12, 2023
8b4a0d0
Merge branch 'mint_test_tokens' of https://github.com/taikoxyz/taiko-…
jscriptcoder Jul 12, 2023
b374fd9
DesltopOrLarger helper component
jscriptcoder Jul 12, 2023
c95e2b7
minor change
jscriptcoder Jul 12, 2023
f9ad657
minor change
jscriptcoder Jul 12, 2023
2606310
Update packages/bridge-ui-v2/src/i18n/en.json
jscriptcoder Jul 12, 2023
c2e7283
fix eslint
jscriptcoder Jul 12, 2023
7834cce
Merge branch 'mint_test_tokens' of https://github.com/taikoxyz/taiko-…
jscriptcoder Jul 12, 2023
1a5c23f
minor change
jscriptcoder Jul 12, 2023
faa1986
rename free to fee
jscriptcoder Jul 12, 2023
888cf3f
typo
jscriptcoder Jul 12, 2023
30570c2
better use of conditions
jscriptcoder Jul 12, 2023
e972b2d
add minor comment
jscriptcoder Jul 12, 2023
c7d11d3
wip
jscriptcoder Jul 12, 2023
61cd279
add checkMintable test
jscriptcoder Jul 12, 2023
0029e85
minor change
jscriptcoder Jul 12, 2023
ae9999a
token minting coverage
jscriptcoder Jul 12, 2023
cb284a8
excluding coverage
jscriptcoder Jul 12, 2023
b18931a
merge main
jscriptcoder Jul 12, 2023
842372e
wip
jscriptcoder Jul 13, 2023
16caf7d
wip
jscriptcoder Jul 13, 2023
5276925
render user balabnce
jscriptcoder Jul 13, 2023
430b0de
error handling
jscriptcoder Jul 13, 2023
1033b55
Merge branch 'main' into account_balance
jscriptcoder Jul 13, 2023
231f686
remove unnecessary comment
jscriptcoder Jul 13, 2023
a6b825a
small comment
jscriptcoder Jul 13, 2023
1f1d2f3
small comment
jscriptcoder Jul 13, 2023
25c0e83
getAddress unit test
jscriptcoder Jul 13, 2023
c415d57
some improvements on test
jscriptcoder Jul 13, 2023
956ae90
some improvements on test
jscriptcoder Jul 13, 2023
978c2ff
wip
jscriptcoder Jul 13, 2023
32f6898
main merge
jscriptcoder Jul 14, 2023
7ade65a
test token functions
jscriptcoder Jul 14, 2023
9f025b1
fix lint
jscriptcoder Jul 14, 2023
44bc91b
mocke libs
jscriptcoder Jul 14, 2023
77240c3
improve tests
jscriptcoder Jul 14, 2023
3f38cee
minor change
jscriptcoder Jul 14, 2023
93d588f
minor change
jscriptcoder Jul 14, 2023
cc05c0f
convert with +
jscriptcoder Jul 14, 2023
4ca3e53
small refactoring
jscriptcoder Jul 14, 2023
519e3e3
better job with account connection
jscriptcoder Jul 14, 2023
8016a40
minor change in the LoadingText
jscriptcoder Jul 14, 2023
9d34a07
recommended fee
jscriptcoder Jul 14, 2023
05bbde5
passing object args
jscriptcoder Jul 14, 2023
8f6e1ce
wip
jscriptcoder Jul 14, 2023
9fe557a
swapping networks
jscriptcoder Jul 14, 2023
66adfd1
wip
jscriptcoder Jul 14, 2023
1e54354
merge main
jscriptcoder Jul 14, 2023
79005fb
minor changes
jscriptcoder Jul 15, 2023
07a8d2a
Merge branch 'main' into recommended_fee
jscriptcoder Jul 17, 2023
af4b8ce
destination network is only used in bridge page
jscriptcoder Jul 17, 2023
1060636
fix lint
jscriptcoder Jul 17, 2023
7b28160
wip
jscriptcoder Jul 17, 2023
a18252f
wip
jscriptcoder Jul 17, 2023
eb8a33b
wip
jscriptcoder Jul 17, 2023
c0c8269
fix lint
jscriptcoder Jul 17, 2023
fe08212
disable None when no ETH on destination
jscriptcoder Jul 17, 2023
629e093
delay option click
jscriptcoder Jul 17, 2023
a7789c8
better ux
jscriptcoder Jul 17, 2023
c34d82a
fix lint
jscriptcoder Jul 17, 2023
a91d737
ProcessingFee component finished
jscriptcoder Jul 17, 2023
6a32a55
minor change
jscriptcoder Jul 17, 2023
da73b13
minor change
jscriptcoder Jul 17, 2023
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
10 changes: 10 additions & 0 deletions packages/bridge-ui-v2/src/app.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const recommentProcessingFee = {
ethGasLimit: BigInt(900000),
erc20NotDeployedGasLimit: BigInt(3100000),
erc20DeployedGasLimit: BigInt(1100000),
};

export const processingFeeComponent = {
closingDelayOptionClick: 300,
intervalComputeRecommendedFee: 20000,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@
import { t } from 'svelte-i18n';

import { successToast, warningToast } from '$components/NotificationToast';
import { account } from '$stores/account';

let prevAccount = $account;
import { OnAccount } from '$components/OnAccount';
import type { Account } from '$stores/account';

// Listen to changes in the account state and notify the user
// when the account is connected or disconnected via toast
account.subscribe((_account) => {
if (_account?.isConnected) {
function onAccountChange(newAccount: Account, oldAccount?: Account) {
if (newAccount?.isConnected) {
successToast($t('messages.account.connected'));
} else if (prevAccount && _account?.isDisconnected) {
} else if (oldAccount && newAccount?.isDisconnected) {
// We check if there was previous account, if not
// the user just hit the app, and there is no need
// to show the message.
warningToast($t('messages.account.disconnected'));
}

prevAccount = _account;
});
}
</script>

<OnAccount change={onAccountChange} />
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

import { Card } from '$components/Card';
import { ChainSelector } from '$components/ChainSelector';
import { srcChain } from '$stores/network';
import { network } from '$stores/network';

import ListWithDetailsView from './ListWithDetailsView.svelte';
import TableView from './TableView.svelte';
</script>

<Card class="md:min-w-[524px]" title={$t('activities.title')} text={$t('activities.subtitle')}>
<div class="space-y-[35px]">
<ChainSelector label={$t('chain_selector.currently_on')} value={$srcChain} />
<ChainSelector label={$t('chain_selector.currently_on')} value={$network} />
<!-- Small size view -->
<div class="md:hidden">
<ListWithDetailsView />
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion packages/bridge-ui-v2/src/components/AmountInput/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<script lang="ts">
import { t } from 'svelte-i18n';

import { InputBox } from '$components/InputBox';
import { uid } from '$libs/util/uid';

import Balance from './Balance.svelte';

let inputId = `input-${uid()}`;
</script>

<div class="AmountInput f-col space-y-2">
<div class="f-between-center text-secondary-content">
<label class="body-regular" for={inputId}>{$t('amount_input.label')}</label>
<Balance />
</div>
<div class="relative f-items-center">
<InputBox
id={inputId}
type="number"
placeholder="0.01"
min="0"
class="w-full input-box outline-none py-6 pr-16 px-[26px] title-subsection-bold placeholder:text-tertiary-content" />
<button class="absolute right-6 uppercase">{$t('amount_input.button.max')}</button>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<script lang="ts">
import type { FetchBalanceResult } from '@wagmi/core';
import { t } from 'svelte-i18n';

import LoadingText from '$components/LoadingText/LoadingText.svelte';
import { getBalance as getTokenBalance, type Token } from '$libs/token';
import { truncateString } from '$libs/util/truncateString';
import { type Account, account } from '$stores/account';
import { network } from '$stores/network';

import { destNetwork, selectedToken } from '../state';

let tokenBalance: Maybe<FetchBalanceResult>;
let computingTokenBalance = false;
let errorComputingTokenBalance = false;

async function updateTokenBalance(token: Maybe<Token>, account?: Account, srcChainId?: number, destChainId?: number) {
if (!token || !account || !account.address) return;

computingTokenBalance = true;
errorComputingTokenBalance = false;

try {
tokenBalance = await getTokenBalance({
token,
destChainId,
userAddress: account.address,
chainId: srcChainId,
});
} catch (error) {
console.error(error);
errorComputingTokenBalance = true;
} finally {
computingTokenBalance = false;
}
}

export function renderTokenBalance(balance: Maybe<FetchBalanceResult>) {
if (!balance) return '0.00';
return `${truncateString(balance.formatted, 6)} ${balance.symbol}`;
}

$: updateTokenBalance($selectedToken, $account, $network?.id, $destNetwork?.id);
</script>

<div class="body-small-regular">
<span>{$t('amount_input.balance')}:</span>
<span>
{#if computingTokenBalance}
<LoadingText mask="0.0000" />
<LoadingText mask="XXX" />
{:else}
{renderTokenBalance(tokenBalance)}
{/if}
</span>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as AmountInput } from './AmountInput.svelte';
54 changes: 39 additions & 15 deletions packages/bridge-ui-v2/src/components/Bridge/Bridge.svelte
Original file line number Diff line number Diff line change
@@ -1,38 +1,58 @@
<script lang="ts">
import { t } from 'svelte-i18n';

import AmountInput from '$components/AmountInput';
import Button from '$components/Button/Button.svelte';
import { Button } from '$components/Button';
import { Card } from '$components/Card';
import { ChainSelector } from '$components/ChainSelector';
import Icon from '$components/Icon/Icon.svelte';
import { ProcessingFee } from '$components/ProcessingFee';
import { RecipientInput } from '$components/RecipientInput';
import { OnAccount } from '$components/OnAccount';
import { OnNetwork } from '$components/OnNetwork';
import { TokenDropdown } from '$components/TokenDropdown';
import { type Token, tokens } from '$libs/token';
import { destChain, srcChain } from '$stores/network';
import { chains } from '$libs/chain';
import { ETHToken, tokens } from '$libs/token';
import type { Account } from '$stores/account';
import { type Network, network } from '$stores/network';

let selectedToken: Token;
import { AmountInput } from './AmountInput';
import { ProcessingFee } from './ProcessingFee';
import { RecipientInput } from './RecipientInput';
import { destNetwork, selectedToken } from './state';
import SwitchChainsButton from './SwitchChainsButton.svelte';

function onNetworkChange(network: Network) {
if (network && chains.length === 2) {
// If there are only two chains, the destination chain will be the other one
const otherChain = chains.find((chain) => chain.id !== network.id);

if (otherChain) destNetwork.set(otherChain);
}
}

function onAccountChange(account: Account) {
if (account && account.isConnected && !$selectedToken) {
$selectedToken = ETHToken;
} else if (account && account.isDisconnected) {
$selectedToken = null;
$destNetwork = null;
}
}
</script>

<Card class="md:w-[524px]" title={$t('bridge.title')} text={$t('bridge.subtitle')}>
<div class="space-y-[35px]">
<div class="space-y-4">
<div class="space-y-2">
<ChainSelector label={$t('chain.from')} value={$srcChain} />
<TokenDropdown {tokens} bind:value={selectedToken} />
<ChainSelector label={$t('chain.from')} value={$network} switchWallet />
<TokenDropdown {tokens} bind:value={$selectedToken} />
</div>

<AmountInput token={selectedToken} />
<AmountInput />

<div class="f-justify-center">
<button class="f-center rounded-full bg-secondary-icon w-[30px] h-[30px]">
<Icon type="up-down" />
</button>
<SwitchChainsButton />
</div>

<div class="space-y-2">
<ChainSelector label={$t('chain.to')} value={$destChain} />
<ChainSelector label={$t('chain.to')} value={$destNetwork} readOnly />
<RecipientInput />
</div>
</div>
Expand All @@ -46,3 +66,7 @@
</Button>
</div>
</Card>

<OnNetwork change={onNetworkChange} />

<OnAccount change={onAccountChange} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<script lang="ts">
import type { Address } from 'abitype';

import { recommendProcessingFee } from '$libs/fee';
import { getBalance, type Token } from '$libs/token';
import { account, network } from '$stores';

import { destNetwork, selectedToken } from '../state';

export let enoughEth: boolean;
export let calculating = false;
export let error = false;

async function compute(token: Maybe<Token>, userAddress?: Address, srcChainId?: number, destChainId?: number) {
if (!token || !userAddress || !srcChainId || !destChainId) {
enoughEth = false;
return;
}

calculating = true;
error = false;

try {
// Get the balance of the user on the destination chain
const destBalance = await getBalance({
token,
userAddress,
chainId: destChainId,
});

// Calculate the recommended amount of ETH needed for processMessage call
const recommendedAmount = await recommendProcessingFee({
token,
destChainId,
srcChainId,
});

// Does the user have enough ETH to claim manually on the destination chain?
enoughEth = destBalance ? destBalance?.value >= recommendedAmount : false;
} catch (err) {
console.error(err);

error = true;
enoughEth = false;
} finally {
calculating = false;
}
}

$: compute($selectedToken, $account?.address, $network?.id, $destNetwork?.id);
</script>
Loading