From dfe1e6d692a51e81b02d51e0e395be9acc75b122 Mon Sep 17 00:00:00 2001 From: Francisco Date: Tue, 28 Mar 2023 11:04:40 +0200 Subject: [PATCH 01/24] ProcessingFee refactoring --- .../src/components/form/BridgeForm.svelte | 23 ++-- .../src/components/form/ProcessingFee.svelte | 108 ------------------ .../form/ProcessingFee/NoneFeeTooltip.svelte | 52 +++++++++ .../form/ProcessingFee/ProcessingFee.svelte | 100 ++++++++++++++++ .../ProcessingFee/ProcessingFeeTooltip.svelte | 31 +++++ .../components/form/ProcessingFee/index.ts | 1 + packages/bridge-ui/src/config.ts | 3 + packages/bridge-ui/src/domain/fee.ts | 1 + packages/bridge-ui/src/fee/processingFees.ts | 3 + 9 files changed, 200 insertions(+), 122 deletions(-) delete mode 100644 packages/bridge-ui/src/components/form/ProcessingFee.svelte create mode 100644 packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte create mode 100644 packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFee.svelte create mode 100644 packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFeeTooltip.svelte create mode 100644 packages/bridge-ui/src/components/form/ProcessingFee/index.ts create mode 100644 packages/bridge-ui/src/config.ts diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte index 256ebd02baf..49a9e0613ab 100644 --- a/packages/bridge-ui/src/components/form/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte @@ -3,12 +3,11 @@ import { LottiePlayer } from '@lottiefiles/svelte-lottie-player'; import { token } from '../../store/token'; - import { processingFee } from '../../store/fee'; import { fromChain, toChain } from '../../store/chain'; import { activeBridge, bridgeType } from '../../store/bridge'; import { signer } from '../../store/signer'; import { BigNumber, Contract, ethers, Signer } from 'ethers'; - import ProcessingFee from './ProcessingFee.svelte'; + import ProcessingFee from './ProcessingFee'; import SelectToken from '../buttons/SelectToken.svelte'; import type { Token } from '../../domain/token'; @@ -21,7 +20,6 @@ transactioner, transactions as transactionsStore, } from '../../store/transactions'; - import { ProcessingFeeMethod } from '../../domain/fee'; import Memo from './Memo.svelte'; import ERC20_ABI from '../../constants/abi/ERC20'; import TokenVaultABI from '../../constants/abi/TokenVault'; @@ -39,20 +37,21 @@ import { providers } from '../../provider/providers'; import { tokenVaults } from '../../vault/tokenVaults'; import { isOnCorrectChain } from '../../utils/isOnCorrectChain'; + import { ProcessingFeeMethod } from '../../domain/fee'; let amount: string; let amountInput: HTMLInputElement; let requiresAllowance: boolean = false; let btnDisabled: boolean = true; let tokenBalance: string; - let customFee: string = '0'; - let recommendedFee: string = '0'; let memo: string = ''; let loading: boolean = false; let isFaucetModalOpen: boolean = false; let memoError: string; let to: string = ''; let showTo: boolean = false; + let feeMethod: ProcessingFeeMethod = ProcessingFeeMethod.RECOMMENDED; + let feeAmount: string = '0'; // TODO: too much going on here. We need to extract // logic and unit test the hell out of all this. @@ -333,10 +332,12 @@ memo: memo, to: showTo && to ? to : await $signer.getAddress(), }); + const requiredGas = gasEstimate.mul(feeData.gasPrice); const userBalance = await $signer.getBalance('latest'); const processingFee = getProcessingFee(); let balanceAvailableForTx = userBalance.sub(requiredGas); + if (processingFee) { balanceAvailableForTx = balanceAvailableForTx.sub(processingFee); } @@ -362,17 +363,11 @@ } function getProcessingFee() { - if ($processingFee === ProcessingFeeMethod.NONE) { + if (feeMethod === ProcessingFeeMethod.NONE) { return undefined; } - if ($processingFee === ProcessingFeeMethod.CUSTOM) { - return BigNumber.from(ethers.utils.parseEther(customFee)); - } - - if ($processingFee === ProcessingFeeMethod.RECOMMENDED) { - return BigNumber.from(ethers.utils.parseEther(recommendedFee)); - } + return BigNumber.from(ethers.utils.parseEther(feeAmount)); } $: getUserBalance($signer, $token, $fromChain); @@ -458,7 +453,7 @@ - + diff --git a/packages/bridge-ui/src/components/form/ProcessingFee.svelte b/packages/bridge-ui/src/components/form/ProcessingFee.svelte deleted file mode 100644 index 37de24a0a90..00000000000 --- a/packages/bridge-ui/src/components/form/ProcessingFee.svelte +++ /dev/null @@ -1,108 +0,0 @@ - - -
-
- (tooltipOpen = true)}> - {$_('bridgeForm.processingFeeLabel')} - -
- - {#if $processingFee === ProcessingFeeMethod.CUSTOM} - - {:else if $processingFee === ProcessingFeeMethod.RECOMMENDED} -
- {recommendedFee} ETH -
- {/if} - -
- {#each Array.from(processingFees) as fee} - - {/each} -
-
- - - -
- The amount you pay the relayer to process your bridge message on the - destination chain. -

-
    -
  • - Recommended: The recommended fee is the lowest fee - that will get your transaction processed in a reasonable amount of - time. -
  • -
  • - Custom: You can set a custom fee for the relayer to - incentivize them to prioritize your request. A lower fee may result in - longer processing time. -
  • -
  • - None: You can select no fee if you want to come back - here and claim the bridged asset yourself. -
  • -
-
-
-
- - diff --git a/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte b/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte new file mode 100644 index 00000000000..89fb4f0f448 --- /dev/null +++ b/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte @@ -0,0 +1,52 @@ + + + +
+ +
+ Selecting None means that you'll require ETH on the receiving + chain in otder to claim the bridged token. Pleas, come back later to manually + claim. +
+ +
+ + +
+ +
+ +
+
+
+ + diff --git a/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFee.svelte b/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFee.svelte new file mode 100644 index 00000000000..1ac69ac1983 --- /dev/null +++ b/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFee.svelte @@ -0,0 +1,100 @@ + + +
+
+ (showProcessingFeeTooltip = true)}> + {$_('bridgeForm.processingFeeLabel')} + +
+ + + {#if method === ProcessingFeeMethod.CUSTOM} + + {:else if method === ProcessingFeeMethod.RECOMMENDED} +
+ {amount} ETH +
+ {/if} + +
+ {#each Array.from(processingFees) as fee} + {@const [feeMethod, { displayText }] = fee} + {@const selected = method === feeMethod} + + + {/each} +
+
+ + + + + diff --git a/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFeeTooltip.svelte b/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFeeTooltip.svelte new file mode 100644 index 00000000000..4bac37572cd --- /dev/null +++ b/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFeeTooltip.svelte @@ -0,0 +1,31 @@ + + + + +
+ The amount you pay the relayer to process your bridge message on the + destination chain. +

+
    +
  • + Recommended: The recommended fee is the lowest fee + that will get your transaction processed in a reasonable amount of + time. +
  • +
  • + Custom: You can set a custom fee for the relayer to + incentivize them to prioritize your request. A lower fee may result in + longer processing time. +
  • +
  • + None: You can select no fee if you want to come back + here and claim the bridged asset yourself. +
  • +
+
+
+
diff --git a/packages/bridge-ui/src/components/form/ProcessingFee/index.ts b/packages/bridge-ui/src/components/form/ProcessingFee/index.ts new file mode 100644 index 00000000000..645d7e05066 --- /dev/null +++ b/packages/bridge-ui/src/components/form/ProcessingFee/index.ts @@ -0,0 +1 @@ +export { default } from './ProcessingFee.svelte'; diff --git a/packages/bridge-ui/src/config.ts b/packages/bridge-ui/src/config.ts new file mode 100644 index 00000000000..f0b417feb5d --- /dev/null +++ b/packages/bridge-ui/src/config.ts @@ -0,0 +1,3 @@ +export const localStoragePrefix = 'bridge-ui'; + +// Add more configuration items here diff --git a/packages/bridge-ui/src/domain/fee.ts b/packages/bridge-ui/src/domain/fee.ts index d27615c0b17..c68f0d0b0b1 100644 --- a/packages/bridge-ui/src/domain/fee.ts +++ b/packages/bridge-ui/src/domain/fee.ts @@ -5,6 +5,7 @@ export enum ProcessingFeeMethod { } export interface ProcessingFeeDetails { + method: ProcessingFeeMethod; displayText: string; timeToConfirm: number; } diff --git a/packages/bridge-ui/src/fee/processingFees.ts b/packages/bridge-ui/src/fee/processingFees.ts index 1991718a298..d61b17dd3f2 100644 --- a/packages/bridge-ui/src/fee/processingFees.ts +++ b/packages/bridge-ui/src/fee/processingFees.ts @@ -6,6 +6,7 @@ export const processingFees: Map = [ ProcessingFeeMethod.RECOMMENDED, { + method: ProcessingFeeMethod.RECOMMENDED, displayText: 'Recommended', timeToConfirm: 15 * 60 * 1000, }, @@ -13,6 +14,7 @@ export const processingFees: Map = [ ProcessingFeeMethod.CUSTOM, { + method: ProcessingFeeMethod.CUSTOM, displayText: 'Custom', timeToConfirm: 15 * 60 * 1000, }, @@ -20,6 +22,7 @@ export const processingFees: Map = [ ProcessingFeeMethod.NONE, { + method: ProcessingFeeMethod.NONE, displayText: 'None', timeToConfirm: 15 * 60 * 1000, }, From fa5a5041502d0f159b0846c123a498a9f48adb92 Mon Sep 17 00:00:00 2001 From: Francisco Date: Tue, 28 Mar 2023 11:25:13 +0200 Subject: [PATCH 02/24] Store value in localStorage --- .../form/ProcessingFee/NoneFeeTooltip.svelte | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte b/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte index 89fb4f0f448..c57c348d76c 100644 --- a/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte +++ b/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte @@ -1,21 +1,40 @@ - + +
@@ -29,7 +48,7 @@ style:border-radius="0.5rem" type="checkbox" id="noShowAgain" - bind:checked={noShowAgain} + bind:checked={noShowAgainCheckbox} class="checkbox checkbox-secundary mr-2" />
From 764b0089bb9f0581c46d8bda9530e725ab5241fa Mon Sep 17 00:00:00 2001 From: Francisco Date: Tue, 28 Mar 2023 11:52:47 +0200 Subject: [PATCH 03/24] Fix storing opt-in/out --- .../src/components/form/ProcessingFee/ProcessingFee.svelte | 1 - packages/bridge-ui/src/store/fee.ts | 6 ------ 2 files changed, 7 deletions(-) delete mode 100644 packages/bridge-ui/src/store/fee.ts diff --git a/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFee.svelte b/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFee.svelte index 1ac69ac1983..3572c381b68 100644 --- a/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFee.svelte +++ b/packages/bridge-ui/src/components/form/ProcessingFee/ProcessingFee.svelte @@ -1,6 +1,5 @@ diff --git a/packages/bridge-ui/src/components/MessageStatusTooltip.svelte b/packages/bridge-ui/src/components/Transactions/MessageStatusTooltip.svelte similarity index 96% rename from packages/bridge-ui/src/components/MessageStatusTooltip.svelte rename to packages/bridge-ui/src/components/Transactions/MessageStatusTooltip.svelte index 4100d4f8a9a..de91ff7d7bf 100644 --- a/packages/bridge-ui/src/components/MessageStatusTooltip.svelte +++ b/packages/bridge-ui/src/components/Transactions/MessageStatusTooltip.svelte @@ -1,5 +1,5 @@ diff --git a/packages/bridge-ui/src/components/Transaction.svelte b/packages/bridge-ui/src/components/Transactions/Transaction.svelte similarity index 87% rename from packages/bridge-ui/src/components/Transaction.svelte rename to packages/bridge-ui/src/components/Transactions/Transaction.svelte index 749cfc1ab5c..368822cc192 100644 --- a/packages/bridge-ui/src/components/Transaction.svelte +++ b/packages/bridge-ui/src/components/Transactions/Transaction.svelte @@ -1,31 +1,32 @@ + + + + + diff --git a/packages/bridge-ui/src/components/form/BridgeForm.svelte b/packages/bridge-ui/src/components/form/BridgeForm.svelte index 49a9e0613ab..a485da08382 100644 --- a/packages/bridge-ui/src/components/form/BridgeForm.svelte +++ b/packages/bridge-ui/src/components/form/BridgeForm.svelte @@ -38,6 +38,7 @@ import { tokenVaults } from '../../vault/tokenVaults'; import { isOnCorrectChain } from '../../utils/isOnCorrectChain'; import { ProcessingFeeMethod } from '../../domain/fee'; + import Button from '../buttons/Button.svelte'; let amount: string; let amountInput: HTMLInputElement; @@ -458,7 +459,7 @@ {#if loading} - + {:else if !requiresAllowance} - + {:else} - + {/if} From 957d587fe269c69f6515fc6898c3e0c46d150d5d Mon Sep 17 00:00:00 2001 From: Francisco Date: Tue, 28 Mar 2023 16:01:02 +0200 Subject: [PATCH 06/24] wip --- .../Transactions/MessageStatusTooltip.svelte | 12 ++++-------- .../src/components/buttons/Button.svelte | 3 +-- .../form/ProcessingFee/NoneFeeTooltip.svelte | 5 ++++- .../bridge-ui/src/components/modals/Modal.svelte | 15 +++++++-------- .../src/components/modals/TooltipModal.svelte | 3 ++- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/packages/bridge-ui/src/components/Transactions/MessageStatusTooltip.svelte b/packages/bridge-ui/src/components/Transactions/MessageStatusTooltip.svelte index de91ff7d7bf..94377dbde9d 100644 --- a/packages/bridge-ui/src/components/Transactions/MessageStatusTooltip.svelte +++ b/packages/bridge-ui/src/components/Transactions/MessageStatusTooltip.svelte @@ -1,4 +1,5 @@ - diff --git a/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte b/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte index c57c348d76c..1a159ba0fe4 100644 --- a/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte +++ b/packages/bridge-ui/src/components/form/ProcessingFee/NoneFeeTooltip.svelte @@ -34,7 +34,10 @@ the user will have to refresh the page to see the message again if they delete the localStorage entry. --> - +
diff --git a/packages/bridge-ui/src/components/modals/Modal.svelte b/packages/bridge-ui/src/components/modals/Modal.svelte index cf82cfaf6b7..3e618fc827b 100644 --- a/packages/bridge-ui/src/components/modals/Modal.svelte +++ b/packages/bridge-ui/src/components/modals/Modal.svelte @@ -1,23 +1,22 @@ - { if (e.key === 'Escape') { onCloseClicked(); } - }} /> + }; + + +