|
3 | 3 | import { AmountRangeInput, Button, Input, Select } from '$components';
|
4 | 4 | import { getBech32AddressLengthFromChain, truncateText } from '$lib/common';
|
5 | 5 | import { InputType } from '$lib/common/enums';
|
6 |
| - import { L2_NATIVE_GAS_TOKEN_DECIMALS } from '$lib/constants'; |
| 6 | + import { |
| 7 | + L2_NATIVE_GAS_TOKEN_DECIMALS, |
| 8 | + L1_BASE_TOKEN_DECIMALS, |
| 9 | + } from '$lib/constants'; |
7 | 10 | import {
|
8 | 11 | appConfiguration,
|
9 | 12 | nodeClient,
|
|
20 | 23 | withdrawStateStore,
|
21 | 24 | } from '$lib/withdraw';
|
22 | 25 |
|
23 |
| - const formInput: WithdrawFormInput = { |
| 26 | + let formInput: WithdrawFormInput = { |
24 | 27 | receiverAddress: '',
|
25 | 28 | baseTokensToSend: storageDeposit,
|
26 | 29 | nativeTokensToSend: {},
|
|
49 | 52 | $: $withdrawStateStore, updateFormInput();
|
50 | 53 | $: placeholderHrp = `${$appConfiguration?.bech32Hrp.toLowerCase()}...`;
|
51 | 54 |
|
| 55 | + $: storageDepositAdjustedDecimals = |
| 56 | + storageDeposit * |
| 57 | + 10 ** (L2_NATIVE_GAS_TOKEN_DECIMALS - L1_BASE_TOKEN_DECIMALS); |
| 58 | +
|
52 | 59 | function updateFormInput() {
|
53 | 60 | if (formInput.baseTokensToSend > $withdrawStateStore.availableBaseTokens) {
|
54 | 61 | formInput.baseTokensToSend = 0;
|
|
132 | 139 | }
|
133 | 140 |
|
134 | 141 | if (result.status) {
|
135 |
| - resetForm(); |
| 142 | + resetView(); |
136 | 143 | showNotification({
|
137 | 144 | type: NotificationType.Success,
|
138 | 145 | message: `Withdraw request sent. BlockIndex: ${result.blockNumber}`,
|
|
221 | 228 | });
|
222 | 229 | };
|
223 | 230 |
|
224 |
| - function resetForm(): void { |
| 231 | + let resetReactiveVariable = 0; // This is a hack to force a re-render of the component |
| 232 | + function resetView(): void { |
225 | 233 | formInput.receiverAddress = '';
|
226 | 234 | formInput.baseTokensToSend = storageDeposit;
|
227 | 235 | formInput.nativeTokensToSend = {};
|
228 | 236 | formInput.nftIDToSend = null;
|
| 237 | + formInput = formInput; |
| 238 | +
|
| 239 | + resetReactiveVariable++; |
229 | 240 | }
|
230 | 241 | </script>
|
231 | 242 |
|
|
255 | 266 | <tokens-to-send-wrapper>
|
256 | 267 | <div class="mb-2">Tokens to send</div>
|
257 | 268 | <info-box class="flex flex-col space-y-4 max-h-96 overflow-auto">
|
258 |
| - <AmountRangeInput |
259 |
| - label="{$appConfiguration?.ticker} Token:" |
260 |
| - bind:value={formInput.baseTokensToSend} |
261 |
| - disabled={!canSetAmountToWithdraw} |
262 |
| - min={storageDeposit} |
263 |
| - max={Math.max( |
264 |
| - $withdrawStateStore.availableBaseTokens - storageDeposit, |
265 |
| - 0, |
266 |
| - )} |
267 |
| - decimals={L2_NATIVE_GAS_TOKEN_DECIMALS} |
268 |
| - /> |
| 269 | + {#key resetReactiveVariable} |
| 270 | + <AmountRangeInput |
| 271 | + label="{$appConfiguration?.ticker} Token:" |
| 272 | + bind:value={formInput.baseTokensToSend} |
| 273 | + disabled={!canSetAmountToWithdraw} |
| 274 | + min={storageDepositAdjustedDecimals} |
| 275 | + max={Math.max( |
| 276 | + $withdrawStateStore.availableBaseTokens - storageDeposit, |
| 277 | + 0, |
| 278 | + )} |
| 279 | + decimals={L2_NATIVE_GAS_TOKEN_DECIMALS} |
| 280 | + /> |
| 281 | + {/key} |
269 | 282 | {#each $withdrawStateStore.availableNativeTokens as nativeToken}
|
270 | 283 | <AmountRangeInput
|
271 | 284 | bind:value={formInput.nativeTokensToSend[nativeToken.id]}
|
|
0 commit comments