-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bridge-ui-v2): bridging ETH and ERC20 (#14225)
- Loading branch information
1 parent
aa5d03d
commit a4aeeee
Showing
50 changed files
with
1,285 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
packages/bridge-ui-v2/src/components/Alert/FlatAlert.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
96
packages/bridge-ui-v2/src/components/Bridge/Actions.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
</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> | ||
{:else} | ||
<span class="body-bold">{$t('bridge.button.bridge')}</span> | ||
{/if} | ||
</Button> | ||
</div> |
Oops, something went wrong.