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): bridging ETH and ERC20 #14225

Merged
merged 77 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
bec2657
minor change
jscriptcoder Jul 17, 2023
20b7d90
Merge branch 'main' into bridge_eth
jscriptcoder Jul 18, 2023
3a84b4f
wip
jscriptcoder Jul 18, 2023
82d6d88
wip
jscriptcoder Jul 19, 2023
8adfaea
wip
jscriptcoder Jul 19, 2023
ce37706
wip
jscriptcoder Jul 19, 2023
614a564
wip
jscriptcoder Jul 19, 2023
ccd044b
max button
jscriptcoder Jul 19, 2023
0c49995
wip
jscriptcoder Jul 19, 2023
2908484
wip
jscriptcoder Jul 19, 2023
a222c3f
wip
jscriptcoder Jul 19, 2023
626b928
wip
jscriptcoder Jul 19, 2023
93ceb18
wip
jscriptcoder Jul 19, 2023
3d9bf59
amount input validation
jscriptcoder Jul 19, 2023
2ab59ae
Merge branch 'main' into bridge_eth
jscriptcoder Jul 19, 2023
1be9386
minor change
jscriptcoder Jul 19, 2023
b1831d7
Merge branch 'bridge_eth' of https://github.com/taikoxyz/taiko-mono i…
jscriptcoder Jul 19, 2023
8d5fbec
minor comment
jscriptcoder Jul 19, 2023
5354874
minor TODO
jscriptcoder Jul 19, 2023
0be1db3
fix test
jscriptcoder Jul 19, 2023
8e51d03
remove unnecessary file
jscriptcoder Jul 19, 2023
5780ea5
fix error
jscriptcoder Jul 19, 2023
3ba05aa
fix ts error
jscriptcoder Jul 19, 2023
9e49964
fix lint
jscriptcoder Jul 19, 2023
c1f27b9
minor change
jscriptcoder Jul 19, 2023
a3b7074
minor change
jscriptcoder Jul 19, 2023
893b37e
fix lint
jscriptcoder Jul 19, 2023
b459d39
align to new design
jscriptcoder Jul 19, 2023
d67cc8e
minor change
jscriptcoder Jul 19, 2023
86189c6
wip
jscriptcoder Jul 19, 2023
a07fd21
wip
jscriptcoder Jul 20, 2023
9621dda
merge main
jscriptcoder Jul 20, 2023
46dbaa3
wip
jscriptcoder Jul 20, 2023
1f64023
wip
jscriptcoder Jul 20, 2023
0691e81
wip
jscriptcoder Jul 20, 2023
9c34ede
wip
jscriptcoder Jul 20, 2023
3b76b8c
wip
jscriptcoder Jul 20, 2023
7587459
wip
jscriptcoder Jul 20, 2023
3c62249
wip
jscriptcoder Jul 20, 2023
4948994
inssuficient balance and allowance
jscriptcoder Jul 20, 2023
348be82
fix ts
jscriptcoder Jul 20, 2023
c46764c
minor change
jscriptcoder Jul 20, 2023
28e4fc6
fix token dropdown
jscriptcoder Jul 20, 2023
785cdd6
wip
jscriptcoder Jul 20, 2023
0caae08
wip
jscriptcoder Jul 20, 2023
41840bf
wip
jscriptcoder Jul 20, 2023
2e619af
wip
jscriptcoder Jul 20, 2023
8a56bc1
new recipient
jscriptcoder Jul 20, 2023
6170b73
add FlatAlert component
jscriptcoder Jul 20, 2023
7f1cf01
Merge branch 'main' into bridge_eth
jscriptcoder Jul 20, 2023
eac90ab
recipient address
jscriptcoder Jul 21, 2023
28364bc
wip
jscriptcoder Jul 21, 2023
4eb1bab
wip
jscriptcoder Jul 21, 2023
8db8e2c
remove Balance component
jscriptcoder Jul 21, 2023
114eeaa
wip
jscriptcoder Jul 21, 2023
5f21367
bridge actions
jscriptcoder Jul 21, 2023
a0951ac
fix lint
jscriptcoder Jul 21, 2023
33893c4
wip
jscriptcoder Jul 21, 2023
51b5010
wip
jscriptcoder Jul 22, 2023
15ac782
wip
jscriptcoder Jul 22, 2023
fa38d1f
wip
jscriptcoder Jul 22, 2023
743e46d
bridging
jscriptcoder Jul 22, 2023
a7b0cfd
handle errors
jscriptcoder Jul 22, 2023
8119d50
wip
jscriptcoder Jul 22, 2023
e074ef7
bridging in place
jscriptcoder Jul 22, 2023
5d5a512
Merge branch 'main' into bridge_eth
jscriptcoder Jul 22, 2023
003d366
wip
jscriptcoder Jul 22, 2023
f504252
fix faucet
jscriptcoder Jul 22, 2023
cc02643
Merge branch 'bridge_eth' of https://github.com/taikoxyz/taiko-mono i…
jscriptcoder Jul 22, 2023
dfdb230
minor change
jscriptcoder Jul 22, 2023
2220283
we do not need this Validator
jscriptcoder Jul 22, 2023
9ee070b
Merge branch 'main' into bridge_eth
jscriptcoder Jul 23, 2023
637b94c
token contains the type
jscriptcoder Jul 24, 2023
31cafce
Merge branch 'bridge_eth' of https://github.com/taikoxyz/taiko-mono i…
jscriptcoder Jul 24, 2023
8bbf73d
fix ts
jscriptcoder Jul 24, 2023
883df6a
fix lint
jscriptcoder Jul 24, 2023
6b6741a
Merge branch 'main' into bridge_eth
jscriptcoder Jul 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/bridge-ui-v2/src/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ export const bridge = {
noOwnerGasLimit: BigInt(140000),
noTokenDeployedGasLimit: BigInt(3000000),
};

export const pendingTransaction = {
waitTimeout: 300000,
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import TableView from './TableView.svelte';
</script>

<Card class="md:min-w-[524px]" title={$t('activities.title')} text={$t('activities.subtitle')}>
<Card class="md:min-w-[524px]" title={$t('activities.title')} text={$t('activities.description')}>
<div class="space-y-[35px]">
<ChainSelector label={$t('chain_selector.currently_on')} value={$network} />
<ChainSelector label={$t('chain_selector.currently_on')} value={$network} small />
<!-- Small size view -->
<div class="md:hidden">
<ListWithDetailsView />
Expand Down
24 changes: 11 additions & 13 deletions packages/bridge-ui-v2/src/components/Alert/Alert.svelte
Original file line number Diff line number Diff line change
@@ -1,49 +1,47 @@
<script lang="ts">
import { classNames } from '$libs/util/classNames';

import { Icon, type IconType } from '../Icon';
import { Icon } from '../Icon';
import type { AlertIconDetails, AlertType } from './types';

type AlertType = 'success' | 'warning' | 'error' | 'info';
type AlertTypeDetails = {
class: string;
iconType: IconType;
iconFillClass: string;
type AlertTypeDetails = AlertIconDetails & {
alertClass: string;
};

export let type: AlertType;
export let forceColumnFlow = false;

let typeMap: Record<AlertType, AlertTypeDetails> = {
success: {
class: 'alert-success',
alertClass: 'alert-success',
iconType: 'check-circle',
iconFillClass: 'fill-success-content',
},
warning: {
class: 'alert-warning',
alertClass: 'alert-warning',
iconType: 'exclamation-circle',
iconFillClass: 'fill-warning-content',
},
error: {
class: 'alert-danger',
alertClass: 'alert-danger',
iconType: 'x-close-circle',
iconFillClass: 'fill-error-content',
},
info: {
class: 'alert-info',
alertClass: 'alert-info',
iconType: 'info-circle',
iconFillClass: 'fill-info-content',
},
};

const { alertClass, iconType, iconFillClass } = typeMap[type];

const classes = classNames(
'alert flex gap-[5px] py-[12px] px-[20px] rounded-[10px]',
type ? typeMap[type].class : null,
type ? alertClass : null,
forceColumnFlow ? 'grid-flow-col text-left' : null,
$$props.class,
);
const iconType = typeMap[type].iconType;
const iconFillClass = typeMap[type].iconFillClass;
</script>

<div class={classes}>
Expand Down
47 changes: 47 additions & 0 deletions packages/bridge-ui-v2/src/components/Alert/FlatAlert.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<script lang="ts">
import { classNames } from '$libs/util/classNames';

import { Icon } from '../Icon';
import type { AlertIconDetails, AlertType } from './types';

type AlertTypeDetails = AlertIconDetails & {
textClass: string;
};

export let type: AlertType;
export let message: string;

let typeMap: Record<AlertType, AlertTypeDetails> = {
success: {
textClass: 'text-positive-sentiment',
iconType: 'check-circle',
iconFillClass: 'fill-success-content',
},
warning: {
textClass: 'text-warning-sentiment',
iconType: 'exclamation-circle',
iconFillClass: 'fill-warning-content',
},
error: {
textClass: 'text-negative-sentiment',
iconType: 'x-close-circle',
iconFillClass: 'fill-error-content',
},
info: {
textClass: 'text-secondary-content',
iconType: 'info-circle',
iconFillClass: 'fill-info-content',
},
};

const { textClass, iconType, iconFillClass } = typeMap[type];

const classes = classNames('f-items-center space-x-1', $$props.class);
</script>

<div class={classes}>
<Icon type={iconType} fillClass={iconFillClass} />
<div class="body-small-regular {textClass}">
{message}
</div>
</div>
1 change: 1 addition & 0 deletions packages/bridge-ui-v2/src/components/Alert/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { default as Alert } from './Alert.svelte';
export { default as FlatAlert } from './FlatAlert.svelte';
8 changes: 8 additions & 0 deletions packages/bridge-ui-v2/src/components/Alert/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { IconType } from '$components/Icon';

export type AlertType = 'success' | 'warning' | 'error' | 'info';

export type AlertIconDetails = {
iconType: IconType;
iconFillClass: string;
};
96 changes: 96 additions & 0 deletions packages/bridge-ui-v2/src/components/Bridge/Actions.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<script lang="ts">
import { t } from 'svelte-i18n';

import { Button } from '$components/Button';
import { Icon } from '$components/Icon';
import { TokenType } from '$libs/token';
import { account, network } from '$stores';

import {
computingBalance,
destNetwork,
enteredAmount,
errorComputingBalance,
insufficientAllowance,
insufficientBalance,
recipientAddress,
selectedToken,
tokenBalance,
} from './state';

export let approve: () => Promise<void>;
export let bridge: () => Promise<void>;

let approving = false;
let bridging = false;

function onApproveClick() {
approving = true;
approve().finally(() => {
approving = false;
});
}

function onBridgeClick() {
bridging = true;
bridge().finally(() => {
bridging = false;
});
}

// TODO: feels like we need a state machine here

// Basic conditions so we can even start the bridging process
$: hasAddress = $recipientAddress || $account?.address;
$: hasNetworks = $network?.id && $destNetwork?.id;
$: hasBalance =
!$computingBalance && !$errorComputingBalance && $tokenBalance?.value && $tokenBalance?.value > BigInt(0);
$: canDoNothing = !hasAddress || !hasNetworks || !hasBalance || !$selectedToken || !$enteredAmount;

// Conditions for approve/bridge steps
$: isSelectedERC20 = $selectedToken && $selectedToken.type === TokenType.ERC20;
$: isTokenApproved = isSelectedERC20 && $enteredAmount && !$insufficientAllowance;

// Conditions to disable/enable buttons
$: disableApprove = canDoNothing || !$insufficientAllowance || approving;
$: disableBridge = canDoNothing || $insufficientAllowance || $insufficientBalance || bridging;

// General loading state
$: loading = approving || bridging;

Check warning on line 59 in packages/bridge-ui-v2/src/components/Bridge/Actions.svelte

View workflow job for this annotation

GitHub Actions / build

'loading' is defined but never used
</script>

<div class="f-between-center w-full gap-4">
{#if isSelectedERC20}
<Button
type="primary"
class="px-[28px] py-[14px] rounded-full flex-1"
disabled={disableApprove}
loading={approving}
on:click={onApproveClick}>
{#if approving}
<span class="body-bold">{$t('bridge.button.approving')}</span>
{:else if isTokenApproved}
<div class="f-items-center">
<Icon type="check" />
<span class="body-bold">{$t('bridge.button.approved')}</span>
</div>
{:else}
<span class="body-bold">{$t('bridge.button.approve')}</span>
{/if}
</Button>
<Icon type="arrow-right" />
{/if}

<Button
type="primary"
class="px-[28px] py-[14px] rounded-full flex-1"
disabled={disableBridge}
loading={bridging}
on:click={onBridgeClick}>
{#if bridging}
<span class="body-bold">{$t('bridge.button.bridging')}</span>
jscriptcoder marked this conversation as resolved.
Show resolved Hide resolved
{:else}
<span class="body-bold">{$t('bridge.button.bridge')}</span>
{/if}
</Button>
</div>