From 099e2bb9bb6a3c18ab013aa47e7776200f16f656 Mon Sep 17 00:00:00 2001 From: mimi Date: Wed, 16 Jun 2021 14:31:17 +0700 Subject: [PATCH 01/10] check if withdrawal reached the daily limit --- src/components/gateway/WithdrawForm.vue | 15 ++++++++++++--- src/locales/en.json | 1 + 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/components/gateway/WithdrawForm.vue b/src/components/gateway/WithdrawForm.vue index 54fedbb8..feecbd41 100644 --- a/src/components/gateway/WithdrawForm.vue +++ b/src/components/gateway/WithdrawForm.vue @@ -33,9 +33,14 @@
{{ $t('components.gateway.withdraw_form_modal.balance') }} {{ balance | tokenAmount(tokenInfo.decimals)}} {{ token }}
-
+
+ {{ $t('components.gateway.withdraw_form_modal.daily_withdrawal_limit_reached') }} + {{ isWithdrawalLimitEnabled | tokenAmount(tokenInfo.decimals) }} {{ token }} +
+
{{ $t('components.gateway.withdraw_form_modal.daily_remaining_withdraw_amount') }} - {{ dailyRemainingWithdrawAmount | tokenAmount(tokenInfo.decimals) }} {{ token }} + {{ dailyRemainingWithdrawAmount | tokenAmount(tokenInfo.decimals) }} / + {{ isWithdrawalLimitEnabled | tokenAmount(tokenInfo.decimals) }} {{ token }}
{{ $t('components.gateway.withdraw_form_modal.withdraw') }} @@ -173,6 +178,10 @@ export default class WithdrawForm extends Vue { this.visible = false } + reachedLimit() { + return this.isWithdrawalLimitEnabled && this.dailyRemainingWithdrawAmount.lte(new BN(0)) + } + setAmountIsError(isError: boolean) { this.amountIsValid = !isError } diff --git a/src/locales/en.json b/src/locales/en.json index 2c9c74c6..33281b13 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -578,6 +578,7 @@ "transfer_fee": "Transfer to {chain} requires a fee of ", "balance": "Your balance : ", "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", + "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", "recipient": "Recipient on {chain}", "withdraw": "Withdraw" } From ae20e02cb64245664a523d4397f59fb7a0aaad16 Mon Sep 17 00:00:00 2001 From: mimi Date: Wed, 16 Jun 2021 14:32:05 +0700 Subject: [PATCH 02/10] add translation keys --- src/locales/es.json | 1 + src/locales/ja.json | 1 + src/locales/ko.json | 1 + src/locales/th.json | 1 + src/locales/zh.json | 1 + 5 files changed, 5 insertions(+) diff --git a/src/locales/es.json b/src/locales/es.json index 99a202a0..8aec674e 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -523,6 +523,7 @@ "transfer_fee": "Transfer to {chain} requires a fee of ", "balance": "Your balance : ", "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", + "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", "recipient": "Recipient on {chain}", "withdraw": "Withdraw" } diff --git a/src/locales/ja.json b/src/locales/ja.json index 4315ea12..d7099c5e 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -523,6 +523,7 @@ "transfer_fee": "Transfer to {chain} requires a fee of ", "balance": "Your balance : ", "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", + "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", "recipient": "Recipient on {chain}", "withdraw": "Withdraw" } diff --git a/src/locales/ko.json b/src/locales/ko.json index 9d16e703..9a4172aa 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -523,6 +523,7 @@ "transfer_fee": "{chain}으로 전송하려면 수수료가 필요합니다.", "balance": "당신의 잔액 : ", "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", + "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", "recipient": "{chain} 상의 수신자", "withdraw": "출금" } diff --git a/src/locales/th.json b/src/locales/th.json index dc626136..0eb33d63 100644 --- a/src/locales/th.json +++ b/src/locales/th.json @@ -523,6 +523,7 @@ "transfer_fee": "Transfer to {chain} requires a fee of ", "balance": "Your balance : ", "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", + "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", "recipient": "Recipient on {chain}", "withdraw": "Withdraw" } diff --git a/src/locales/zh.json b/src/locales/zh.json index f2ba552c..e0a18a41 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -523,6 +523,7 @@ "transfer_fee": "转移到 {chain} 需要手续费 ", "balance": "你的余额: ", "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", + "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", "recipient": "{chain} 上的接受者", "withdraw": "提取" } From e07b40e740984fc3873a87defecd3332da9f9715 Mon Sep 17 00:00:00 2001 From: mimi Date: Wed, 16 Jun 2021 14:51:33 +0700 Subject: [PATCH 03/10] custom error for daily withdrawal limit reached --- src/locales/en.json | 1 + src/locales/es.json | 1 + src/locales/ja.json | 1 + src/locales/ko.json | 1 + src/locales/th.json | 1 + src/locales/zh.json | 1 + src/store/gateway/plasma.ts | 6 +++++- 7 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/locales/en.json b/src/locales/en.json index 33281b13..c1dbf83c 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -885,6 +885,7 @@ "could_not_deposit_eth": "Could not deposit ETH, please make sure you pay enough gas for the transaction.", "deposit_approval_failed": "Deposit approval failed.", "withdraw_failed": "Withdraw failed, please try again or contact support.", + "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "The supplied key is already mapped.", "unexpected_error_while_add_account": "Unexpected error while adding account mapping.", "balance_not_enough": "Your balance isn't enough. Please deposit first.", diff --git a/src/locales/es.json b/src/locales/es.json index 8aec674e..87542fb0 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -830,6 +830,7 @@ "could_not_deposit_eth": "Could not deposit ETH, please make sure you pay enough gas for the transaction.", "deposit_approval_failed": "Deposit approval failed.", "withdraw_failed": "Withdraw failed, please try again or contact support.", + "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "The supplied key is already mapped.", "unexpected_error_while_add_account": "Unexpected error while adding account mapping.", "balance_not_enough": "Your balance isn't enough. Please deposit first.", diff --git a/src/locales/ja.json b/src/locales/ja.json index d7099c5e..b9ccb192 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -830,6 +830,7 @@ "could_not_deposit_eth": "Could not deposit ETH, please make sure you pay enough gas for the transaction.", "deposit_approval_failed": "Deposit approval failed.", "withdraw_failed": "Withdraw failed, please try again or contact support.", + "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "The supplied key is already mapped.", "unexpected_error_while_add_account": "Unexpected error while adding account mapping.", "balance_not_enough": "Your balance isn't enough. Please deposit first.", diff --git a/src/locales/ko.json b/src/locales/ko.json index 9a4172aa..26a7ebc4 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -830,6 +830,7 @@ "could_not_deposit_eth": "ETH를 입금할 수 없습니다. 트랜잭션 처리에 충분한 가스 수수료를 지불했는지 확인하세요.", "deposit_approval_failed": "입금 승인 실패", "withdraw_failed": "출금에 실패하였습니다. 다시 시도하거나 고객센터에 문의하세요.", + "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "제공된 키가 이미 매핑되었습니다.", "unexpected_error_while_add_account": "계정 매핑을 추가하던 중 예상치 못한 오류가 발생했습니다.", "balance_not_enough": "잔액이 충분하지 않습니다. 먼저 자금을 입금하세요.", diff --git a/src/locales/th.json b/src/locales/th.json index 0eb33d63..ab69b954 100644 --- a/src/locales/th.json +++ b/src/locales/th.json @@ -830,6 +830,7 @@ "could_not_deposit_eth": "Could not deposit ETH, please make sure you pay enough gas for the transaction.", "deposit_approval_failed": "Deposit approval failed.", "withdraw_failed": "Withdraw failed, please try again or contact support.", + "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "The supplied key is already mapped.", "unexpected_error_while_add_account": "Unexpected error while adding account mapping.", "balance_not_enough": "Your balance isn't enough. Please deposit first.", diff --git a/src/locales/zh.json b/src/locales/zh.json index e0a18a41..e0535c44 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -830,6 +830,7 @@ "could_not_deposit_eth": "不能存入 ETH,请确认为此事务支付足够的 gas 费。", "deposit_approval_failed": "存入批准失败。", "withdraw_failed": "提取出错,请重试或联系客服。", + "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "提供的密钥已映射。", "unexpected_error_while_add_account": "添加账户映射时出现意外错误。", "balance_not_enough": "你的余额不足。请先存入一些。", diff --git a/src/store/gateway/plasma.ts b/src/store/gateway/plasma.ts index 2b23debc..4d2c65b0 100644 --- a/src/store/gateway/plasma.ts +++ b/src/store/gateway/plasma.ts @@ -334,7 +334,11 @@ export async function plasmaWithdraw(context: ActionContext, funds: Funds) { return } feedback.endTask() - feedback.showError(i18n.t("feedback_msg.error.withdraw_failed").toString()) + if (error.message.includes("limit reached")) { + feedback.showError(i18n.t("feedback_msg.error.withdraw_failed_limit_reached").toString()) + } else { + feedback.showError(i18n.t("feedback_msg.error.withdraw_failed").toString()) + } Sentry.withScope((scope) => { scope.setExtra("plasmaWithdraw", { withdraw: JSON.stringify({ From 0ee7bdb7f0900f014db70fb1ad84ea0cb6a87864 Mon Sep 17 00:00:00 2001 From: mimi Date: Fri, 18 Jun 2021 11:35:03 +0700 Subject: [PATCH 04/10] using maxPerAccountDailyWithdrawalAmount insteads --- src/components/gateway/WithdrawForm.vue | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/components/gateway/WithdrawForm.vue b/src/components/gateway/WithdrawForm.vue index feecbd41..dcf2bdd6 100644 --- a/src/components/gateway/WithdrawForm.vue +++ b/src/components/gateway/WithdrawForm.vue @@ -33,14 +33,14 @@
{{ $t('components.gateway.withdraw_form_modal.balance') }} {{ balance | tokenAmount(tokenInfo.decimals)}} {{ token }}
-
+
{{ $t('components.gateway.withdraw_form_modal.daily_withdrawal_limit_reached') }} {{ isWithdrawalLimitEnabled | tokenAmount(tokenInfo.decimals) }} {{ token }}
-
+
{{ $t('components.gateway.withdraw_form_modal.daily_remaining_withdraw_amount') }} {{ dailyRemainingWithdrawAmount | tokenAmount(tokenInfo.decimals) }} / - {{ isWithdrawalLimitEnabled | tokenAmount(tokenInfo.decimals) }} {{ token }} + {{ maxPerAccountDailyWithdrawalAmount | tokenAmount(tokenInfo.decimals) }} {{ token }}
{{ $t('components.gateway.withdraw_form_modal.withdraw') }} @@ -109,6 +109,7 @@ export default class WithdrawForm extends Vue { isValidAddress: boolean = false recepient = "" dailyRemainingWithdrawAmount: BN = ZERO + maxPerAccountDailyWithdrawalAmount: BN = ZERO tokenInfo: TokenData | null = null @@ -178,7 +179,7 @@ export default class WithdrawForm extends Vue { this.visible = false } - reachedLimit() { + get reachedLimit() { return this.isWithdrawalLimitEnabled && this.dailyRemainingWithdrawAmount.lte(new BN(0)) } @@ -220,10 +221,9 @@ export default class WithdrawForm extends Vue { if (lastWithdrawalLimitResetDate.toDateString() !== todayDate.toDateString()) { totalWithdrawalAmount = new BN(0) } - const gatewayState = await gateway.getGatewayState() - const maxPerAccountDailyWithdrawalAmount: BN = gatewayState!.maxPerAccountDailyWithdrawalAmount - const remainingWithdrawAmount = maxPerAccountDailyWithdrawalAmount.sub(totalWithdrawalAmount) + this.maxPerAccountDailyWithdrawalAmount = gatewayState!.maxPerAccountDailyWithdrawalAmount + const remainingWithdrawAmount = this.maxPerAccountDailyWithdrawalAmount.sub(totalWithdrawalAmount) console.log("remainingWithdrawAmount: ", remainingWithdrawAmount.toString()) return remainingWithdrawAmount From 10039e0b37dc6a5bad2c13e784307fa3010af445 Mon Sep 17 00:00:00 2001 From: mimi Date: Fri, 18 Jun 2021 11:44:01 +0700 Subject: [PATCH 05/10] using gateway error codes for catch error --- src/locales/en.json | 3 ++- src/locales/es.json | 3 ++- src/locales/ja.json | 3 ++- src/locales/ko.json | 3 ++- src/locales/th.json | 3 ++- src/locales/zh.json | 3 ++- src/store/gateway/plasma.ts | 6 ++++-- 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index c1dbf83c..7a53467b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -885,7 +885,8 @@ "could_not_deposit_eth": "Could not deposit ETH, please make sure you pay enough gas for the transaction.", "deposit_approval_failed": "Deposit approval failed.", "withdraw_failed": "Withdraw failed, please try again or contact support.", - "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_total_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_account_limit_reached": "Account daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "The supplied key is already mapped.", "unexpected_error_while_add_account": "Unexpected error while adding account mapping.", "balance_not_enough": "Your balance isn't enough. Please deposit first.", diff --git a/src/locales/es.json b/src/locales/es.json index 87542fb0..2920a57e 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -830,7 +830,8 @@ "could_not_deposit_eth": "Could not deposit ETH, please make sure you pay enough gas for the transaction.", "deposit_approval_failed": "Deposit approval failed.", "withdraw_failed": "Withdraw failed, please try again or contact support.", - "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_total_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_account_limit_reached": "Account daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "The supplied key is already mapped.", "unexpected_error_while_add_account": "Unexpected error while adding account mapping.", "balance_not_enough": "Your balance isn't enough. Please deposit first.", diff --git a/src/locales/ja.json b/src/locales/ja.json index b9ccb192..6526f30c 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -830,7 +830,8 @@ "could_not_deposit_eth": "Could not deposit ETH, please make sure you pay enough gas for the transaction.", "deposit_approval_failed": "Deposit approval failed.", "withdraw_failed": "Withdraw failed, please try again or contact support.", - "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_total_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_account_limit_reached": "Account daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "The supplied key is already mapped.", "unexpected_error_while_add_account": "Unexpected error while adding account mapping.", "balance_not_enough": "Your balance isn't enough. Please deposit first.", diff --git a/src/locales/ko.json b/src/locales/ko.json index 26a7ebc4..f605d40e 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -830,7 +830,8 @@ "could_not_deposit_eth": "ETH를 입금할 수 없습니다. 트랜잭션 처리에 충분한 가스 수수료를 지불했는지 확인하세요.", "deposit_approval_failed": "입금 승인 실패", "withdraw_failed": "출금에 실패하였습니다. 다시 시도하거나 고객센터에 문의하세요.", - "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_total_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_account_limit_reached": "Account daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "제공된 키가 이미 매핑되었습니다.", "unexpected_error_while_add_account": "계정 매핑을 추가하던 중 예상치 못한 오류가 발생했습니다.", "balance_not_enough": "잔액이 충분하지 않습니다. 먼저 자금을 입금하세요.", diff --git a/src/locales/th.json b/src/locales/th.json index ab69b954..95e5da47 100644 --- a/src/locales/th.json +++ b/src/locales/th.json @@ -830,7 +830,8 @@ "could_not_deposit_eth": "Could not deposit ETH, please make sure you pay enough gas for the transaction.", "deposit_approval_failed": "Deposit approval failed.", "withdraw_failed": "Withdraw failed, please try again or contact support.", - "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_total_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_account_limit_reached": "Account daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "The supplied key is already mapped.", "unexpected_error_while_add_account": "Unexpected error while adding account mapping.", "balance_not_enough": "Your balance isn't enough. Please deposit first.", diff --git a/src/locales/zh.json b/src/locales/zh.json index e0535c44..29fe82ae 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -830,7 +830,8 @@ "could_not_deposit_eth": "不能存入 ETH,请确认为此事务支付足够的 gas 费。", "deposit_approval_failed": "存入批准失败。", "withdraw_failed": "提取出错,请重试或联系客服。", - "withdraw_failed_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_total_limit_reached": "Total daily withdrawal limit has been reached, please try again tomorrow.", + "withdraw_failed_account_limit_reached": "Account daily withdrawal limit has been reached, please try again tomorrow.", "supplied_key_already_mapped": "提供的密钥已映射。", "unexpected_error_while_add_account": "添加账户映射时出现意外错误。", "balance_not_enough": "你的余额不足。请先存入一些。", diff --git a/src/store/gateway/plasma.ts b/src/store/gateway/plasma.ts index 4d2c65b0..257b46e4 100644 --- a/src/store/gateway/plasma.ts +++ b/src/store/gateway/plasma.ts @@ -334,8 +334,10 @@ export async function plasmaWithdraw(context: ActionContext, funds: Funds) { return } feedback.endTask() - if (error.message.includes("limit reached")) { - feedback.showError(i18n.t("feedback_msg.error.withdraw_failed_limit_reached").toString()) + if (error.message.includes("TG024")) { + feedback.showError(i18n.t("feedback_msg.error.withdraw_failed_total_limit_reached").toString()) + } else if (error.message.includes("TG025")) { + feedback.showError(i18n.t("feedback_msg.error.withdraw_failed_account_limit_reached").toString()) } else { feedback.showError(i18n.t("feedback_msg.error.withdraw_failed").toString()) } From b125cd977b3136bcfcfd3ca85cf85af08581cd04 Mon Sep 17 00:00:00 2001 From: mimi Date: Fri, 18 Jun 2021 11:47:06 +0700 Subject: [PATCH 06/10] maxPerAccountDailyWithdrawalAmount instead of isWithdrawalLimitEnabled --- src/components/gateway/WithdrawForm.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/gateway/WithdrawForm.vue b/src/components/gateway/WithdrawForm.vue index dcf2bdd6..941acd2f 100644 --- a/src/components/gateway/WithdrawForm.vue +++ b/src/components/gateway/WithdrawForm.vue @@ -35,7 +35,7 @@
{{ $t('components.gateway.withdraw_form_modal.balance') }} {{ balance | tokenAmount(tokenInfo.decimals)}} {{ token }}
{{ $t('components.gateway.withdraw_form_modal.daily_withdrawal_limit_reached') }} - {{ isWithdrawalLimitEnabled | tokenAmount(tokenInfo.decimals) }} {{ token }} + {{ maxPerAccountDailyWithdrawalAmount | tokenAmount(tokenInfo.decimals) }} {{ token }}
{{ $t('components.gateway.withdraw_form_modal.daily_remaining_withdraw_amount') }} From 053ad7414ca374eab90aee458e7543605862eaed Mon Sep 17 00:00:00 2001 From: Vadim Macagon Date: Tue, 3 Aug 2021 00:30:38 +0700 Subject: [PATCH 07/10] Tweak message shown when daily withdrawal limit is reached --- src/components/gateway/WithdrawForm.vue | 42 ++++++++++++++----------- src/locales/en.json | 6 ++-- src/locales/es.json | 6 ++-- src/locales/ja.json | 6 ++-- src/locales/ko.json | 6 ++-- src/locales/th.json | 6 ++-- src/locales/zh.json | 6 ++-- 7 files changed, 42 insertions(+), 36 deletions(-) diff --git a/src/components/gateway/WithdrawForm.vue b/src/components/gateway/WithdrawForm.vue index 941acd2f..213f3bc1 100644 --- a/src/components/gateway/WithdrawForm.vue +++ b/src/components/gateway/WithdrawForm.vue @@ -33,16 +33,21 @@
{{ $t('components.gateway.withdraw_form_modal.balance') }} {{ balance | tokenAmount(tokenInfo.decimals)}} {{ token }}
-
- {{ $t('components.gateway.withdraw_form_modal.daily_withdrawal_limit_reached') }} - {{ maxPerAccountDailyWithdrawalAmount | tokenAmount(tokenInfo.decimals) }} {{ token }} +
+ {{ + $t('components.gateway.withdraw_form_modal.daily_withdrawal_limit_reached', { + amount: formattedMaxPerAccountDailyWithdrawalAmount, + token + }) + }}
-
+
{{ $t('components.gateway.withdraw_form_modal.daily_remaining_withdraw_amount') }} - {{ dailyRemainingWithdrawAmount | tokenAmount(tokenInfo.decimals) }} / - {{ maxPerAccountDailyWithdrawalAmount | tokenAmount(tokenInfo.decimals) }} {{ token }} + {{ dailyRemainingWithdrawAmount | tokenAmount(tokenInfo.decimals) }} / + {{ maxPerAccountDailyWithdrawalAmount | tokenAmount(tokenInfo.decimals) }} {{ token }}
{{ $t('components.gateway.withdraw_form_modal.withdraw') }} @@ -91,6 +96,7 @@ import { LocalAddress, Address } from "loom-js" import * as plasmaGateways from "@/store/gateway/plasma" import { tokenService, TokenData } from "@/services/TokenService" +import { formatTokenAmount } from "@/filters" @Component({ components: { @@ -144,6 +150,13 @@ export default class WithdrawForm extends Vue { get isWithdrawalLimitEnabled() { return this.state.gateway.withdrawalLimit + && (this.transferRequest.token === "ETH" || this.transferRequest.token === "LOOM") + } + + get formattedMaxPerAccountDailyWithdrawalAmount(): string { + return formatTokenAmount( + this.maxPerAccountDailyWithdrawalAmount, this.tokenInfo ? this.tokenInfo.decimals : 18, + ) } get visible() { @@ -171,15 +184,11 @@ export default class WithdrawForm extends Vue { return this.isValidAddress = isValid } - isCheckDailyRemainingWithdrawAmount() { - return this.transferRequest.token === "ETH" || this.transferRequest.token === "LOOM" - } - close() { this.visible = false } - get reachedLimit() { + get isWithdrawalLimitReached() { return this.isWithdrawalLimitEnabled && this.dailyRemainingWithdrawAmount.lte(new BN(0)) } @@ -205,7 +214,7 @@ export default class WithdrawForm extends Vue { return true } - async remainWithdrawAmount() { + async fetchRemainingWithdrawalAmount() { const { chain, token } = this.transferRequest const gateway = plasmaGateways.service().get(chain, token) @@ -234,8 +243,8 @@ export default class WithdrawForm extends Vue { if (!visible) return const { chain, token } = this.transferRequest const fee = plasmaGateways.service().get(chain, token).fee - if (this.isWithdrawalLimitEnabled && this.isCheckDailyRemainingWithdrawAmount()) { - this.dailyRemainingWithdrawAmount = await this.remainWithdrawAmount() + if (this.isWithdrawalLimitEnabled) { + this.dailyRemainingWithdrawAmount = await this.fetchRemainingWithdrawalAmount() this.max = this.balance.lt(this.dailyRemainingWithdrawAmount) ? this.balance : this.dailyRemainingWithdrawAmount } else { this.max = this.balance @@ -251,9 +260,6 @@ export default class WithdrawForm extends Vue { this.fee = {} } this.tokenInfo = tokenService.getTokenbySymbol(this.transferRequest.token) - if (this.isWithdrawalLimitEnabled) { - this.dailyRemainingWithdrawAmount = await this.remainWithdrawAmount() - } } async requestWithdrawal(e) { diff --git a/src/locales/en.json b/src/locales/en.json index 7a53467b..bdad2e10 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -576,9 +576,9 @@ "withdraw_form_modal": { "title": "Withdraw {token} to {chain}", "transfer_fee": "Transfer to {chain} requires a fee of ", - "balance": "Your balance : ", - "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", - "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", + "balance": "Your balance: ", + "daily_remaining_withdraw_amount": "Daily remaining withdrawal amount: ", + "daily_withdrawal_limit_reached": "You've reached your daily withdrawal limit of {amount} {token}, please try again later.", "recipient": "Recipient on {chain}", "withdraw": "Withdraw" } diff --git a/src/locales/es.json b/src/locales/es.json index 2920a57e..8cf2b9ca 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -521,9 +521,9 @@ "withdraw_form_modal": { "title": "Withdraw {token} to {chain}", "transfer_fee": "Transfer to {chain} requires a fee of ", - "balance": "Your balance : ", - "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", - "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", + "balance": "Your balance: ", + "daily_remaining_withdraw_amount": "Daily remaining withdrawal amount: ", + "daily_withdrawal_limit_reached": "You've reached your daily withdrawal limit of {amount} {token}, please try again later.", "recipient": "Recipient on {chain}", "withdraw": "Withdraw" } diff --git a/src/locales/ja.json b/src/locales/ja.json index 6526f30c..1761bf8f 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -521,9 +521,9 @@ "withdraw_form_modal": { "title": "Withdraw {token} to {chain}", "transfer_fee": "Transfer to {chain} requires a fee of ", - "balance": "Your balance : ", - "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", - "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", + "balance": "Your balance: ", + "daily_remaining_withdraw_amount": "Daily remaining withdrawal amount: ", + "daily_withdrawal_limit_reached": "You've reached your daily withdrawal limit of {amount} {token}, please try again later.", "recipient": "Recipient on {chain}", "withdraw": "Withdraw" } diff --git a/src/locales/ko.json b/src/locales/ko.json index f605d40e..1ddc054f 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -521,9 +521,9 @@ "withdraw_form_modal": { "title": "{chain}으로 {token} 출금", "transfer_fee": "{chain}으로 전송하려면 수수료가 필요합니다.", - "balance": "당신의 잔액 : ", - "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", - "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", + "balance": "Your balance: ", + "daily_remaining_withdraw_amount": "Daily remaining withdrawal amount: ", + "daily_withdrawal_limit_reached": "You've reached your daily withdrawal limit of {amount} {token}, please try again later.", "recipient": "{chain} 상의 수신자", "withdraw": "출금" } diff --git a/src/locales/th.json b/src/locales/th.json index 95e5da47..4cb929f1 100644 --- a/src/locales/th.json +++ b/src/locales/th.json @@ -521,9 +521,9 @@ "withdraw_form_modal": { "title": "Withdraw {token} to {chain}", "transfer_fee": "Transfer to {chain} requires a fee of ", - "balance": "Your balance : ", - "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", - "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", + "balance": "Your balance: ", + "daily_remaining_withdraw_amount": "Daily remaining withdrawal amount: ", + "daily_withdrawal_limit_reached": "You've reached your daily withdrawal limit of {amount} {token}, please try again later.", "recipient": "Recipient on {chain}", "withdraw": "Withdraw" } diff --git a/src/locales/zh.json b/src/locales/zh.json index 29fe82ae..a178c2d3 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -521,9 +521,9 @@ "withdraw_form_modal": { "title": "提取 {token} 到 {chain}", "transfer_fee": "转移到 {chain} 需要手续费 ", - "balance": "你的余额: ", - "daily_remaining_withdraw_amount": "Daily remaining withdraw amount: ", - "daily_withdrawal_limit_reached": "Daily withdrawal limit reached", + "balance": "Your balance: ", + "daily_remaining_withdraw_amount": "Daily remaining withdrawal amount: ", + "daily_withdrawal_limit_reached": "You've reached your daily withdrawal limit of {amount} {token}, please try again later.", "recipient": "{chain} 上的接受者", "withdraw": "提取" } From 3a072eb7597d8fa302004f3c28a2bb9cb78744af Mon Sep 17 00:00:00 2001 From: Vadim Macagon Date: Tue, 3 Aug 2021 00:32:37 +0700 Subject: [PATCH 08/10] Fix upper/lower amount limit messages on the AmountInput --- src/locales/en.json | 4 ++-- src/locales/es.json | 4 ++-- src/locales/ja.json | 4 ++-- src/locales/ko.json | 4 ++-- src/locales/th.json | 4 ++-- src/locales/zh.json | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/locales/en.json b/src/locales/en.json index bdad2e10..3d24112b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -32,8 +32,8 @@ "receiver_addr_err_tx": "Invalid receiver address", "invalid_amount": "Invalid amount", "invalid_addr": "Invalid receiver address", - "amount_input_should_less": "Amount should be less than {amount}", - "amount_input_should_more": "Amount should be more than {amount}", + "amount_input_should_less": "Amount should not exceed {amount}", + "amount_input_should_more": "Amount should be at least {amount}", "amount_input_invalid_amount": "Please enter a valid amount", "amount_input_only_round_amount": "Only round amounts allowed", "awaiting_transaction": "Awaiting transaction confirmation", diff --git a/src/locales/es.json b/src/locales/es.json index 8cf2b9ca..c4364f0c 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -32,8 +32,8 @@ "receiver_addr_err_tx": "Invalid receiver address", "invalid_amount": "Invalid amount", "invalid_addr": "Invalid receiver address", - "amount_input_should_less": "Amount should be less than {amount}", - "amount_input_should_more": "Amount should be more than {amount}", + "amount_input_should_less": "Amount should not exceed {amount}", + "amount_input_should_more": "Amount should be at least {amount}", "amount_input_invalid_amount": "Please enter a valid amount", "amount_input_only_round_amount": "Only round amounts allowed", "awaiting_transaction": "Awaiting transaction confirmation", diff --git a/src/locales/ja.json b/src/locales/ja.json index 1761bf8f..ac12bb3a 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -32,8 +32,8 @@ "receiver_addr_err_tx": "無効な受け取りアドレスです", "invalid_amount": "無効な数量です", "invalid_addr": "無効な受け取りアドレスです", - "amount_input_should_less": "Amount should be less than {amount}", - "amount_input_should_more": "Amount should be more than {amount}", + "amount_input_should_less": "Amount should not exceed {amount}", + "amount_input_should_more": "Amount should be at least {amount}", "amount_input_invalid_amount": "Please enter a valid amount", "amount_input_only_round_amount": "Only round amounts allowed", "awaiting_transaction": "トランザクションの承認待ちです", diff --git a/src/locales/ko.json b/src/locales/ko.json index 1ddc054f..2ca0e182 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -32,8 +32,8 @@ "receiver_addr_err_tx": "유효하지 않은 수신자 주소입니다.", "invalid_amount": "유효하지 않은 숫자입니다.", "invalid_addr": "유효하지 않은 수신자 주소입니다.", - "amount_input_should_less": "{amount} 보다 적어야 합니다.", - "amount_input_should_more": "{amount} 보다 많아야 합니다.", + "amount_input_should_less": "Amount should not exceed {amount}", + "amount_input_should_more": "Amount should be at least {amount}", "amount_input_invalid_amount": "유효한 금액을 입력해주세요", "amount_input_only_round_amount": "소수점 없는 정수 금액만 가능합니다.", "awaiting_transaction": "트랜잭션 확인을 기다리는 중입니다.", diff --git a/src/locales/th.json b/src/locales/th.json index 4cb929f1..d85bed59 100644 --- a/src/locales/th.json +++ b/src/locales/th.json @@ -32,8 +32,8 @@ "receiver_addr_err_tx": "Invalid receiver address", "invalid_amount": "Invalid amount", "invalid_addr": "Invalid receiver address", - "amount_input_should_less": "Amount should be less than {amount}", - "amount_input_should_more": "Amount should be more than {amount}", + "amount_input_should_less": "Amount should not exceed {amount}", + "amount_input_should_more": "Amount should be at least {amount}", "amount_input_invalid_amount": "Please enter a valid amount", "amount_input_only_round_amount": "Only round amounts allowed", "awaiting_transaction": "Awaiting transaction confirmation", diff --git a/src/locales/zh.json b/src/locales/zh.json index a178c2d3..6f67e025 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -32,8 +32,8 @@ "receiver_addr_err_tx": "无效的接收者地址", "invalid_amount": "无效的数量", "invalid_addr": "无效的接收者地址", - "amount_input_should_less": "数量应少于 {amount}", - "amount_input_should_more": "数量应多于 {amount}", + "amount_input_should_less": "Amount should not exceed {amount}", + "amount_input_should_more": "Amount should be at least {amount}", "amount_input_invalid_amount": "请输入一个有效的数量", "amount_input_only_round_amount": "只接受整数", "awaiting_transaction": "正在等待交易确认", From 834ada499c413cc3654b4fc6448eb700125f453e Mon Sep 17 00:00:00 2001 From: Vadim Macagon Date: Wed, 4 Aug 2021 16:40:24 +0700 Subject: [PATCH 09/10] Fix withdrawal limit reset computation The reset time was incorrectly computed using the current locale time instead of UTC time. --- src/components/gateway/WithdrawForm.vue | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/components/gateway/WithdrawForm.vue b/src/components/gateway/WithdrawForm.vue index 213f3bc1..b9be21b4 100644 --- a/src/components/gateway/WithdrawForm.vue +++ b/src/components/gateway/WithdrawForm.vue @@ -98,6 +98,8 @@ import * as plasmaGateways from "@/store/gateway/plasma" import { tokenService, TokenData } from "@/services/TokenService" import { formatTokenAmount } from "@/filters" +const ONE_DAY_MSECS = 86400000 // 24hrs in milliseconds + @Component({ components: { AmountInput, @@ -219,23 +221,17 @@ export default class WithdrawForm extends Vue { const gateway = plasmaGateways.service().get(chain, token) const ownerAddress = Address.fromString(`${this.state.plasma.chainId}:${this.state.plasma.address}`) - const plasmaAccountInfo = await gateway.getLocalAccountInfo(ownerAddress) - let totalWithdrawalAmount: BN = plasmaAccountInfo!.totalWithdrawalAmount - - const lastWithdrawalLimitResetTime: number = plasmaAccountInfo!.lastWithdrawalLimitResetTime - const lastWithdrawalLimitResetDate: Date = new Date(lastWithdrawalLimitResetTime * 1000) - const todayDate: Date = new Date() - - // if lastWithdrawalLimitResetDate is not today then set total withdraw amount of this account to 0 - if (lastWithdrawalLimitResetDate.toDateString() !== todayDate.toDateString()) { + const plasmaAccountInfo = await gateway.getLocalAccountInfo(ownerAddress) + let totalWithdrawalAmount = plasmaAccountInfo.totalWithdrawalAmount + const lastWithdrawalLimitResetTime = plasmaAccountInfo.lastWithdrawalLimitResetTime * 1000 + const elapsedMSecs = Date.now() - lastWithdrawalLimitResetTime + // daily withdrawal limit is reset every 24 hours + if (elapsedMSecs > ONE_DAY_MSECS) { totalWithdrawalAmount = new BN(0) } const gatewayState = await gateway.getGatewayState() - this.maxPerAccountDailyWithdrawalAmount = gatewayState!.maxPerAccountDailyWithdrawalAmount - const remainingWithdrawAmount = this.maxPerAccountDailyWithdrawalAmount.sub(totalWithdrawalAmount) - - console.log("remainingWithdrawAmount: ", remainingWithdrawAmount.toString()) - return remainingWithdrawAmount + this.maxPerAccountDailyWithdrawalAmount = gatewayState.maxPerAccountDailyWithdrawalAmount + return this.maxPerAccountDailyWithdrawalAmount.sub(totalWithdrawalAmount) } @Watch("visible") From 1769183fc20d12e122c23198b8508a849e29a6d4 Mon Sep 17 00:00:00 2001 From: Vadim Macagon Date: Thu, 5 Aug 2021 00:33:00 +0700 Subject: [PATCH 10/10] Don't show the remaining withdrawal amount by default Wait until the remaining withdrawal amount is known before displaying it --- src/components/gateway/WithdrawForm.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/gateway/WithdrawForm.vue b/src/components/gateway/WithdrawForm.vue index b9be21b4..a2aa48f5 100644 --- a/src/components/gateway/WithdrawForm.vue +++ b/src/components/gateway/WithdrawForm.vue @@ -41,7 +41,7 @@ }) }} -
+
{{ $t('components.gateway.withdraw_form_modal.daily_remaining_withdraw_amount') }} {{ dailyRemainingWithdrawAmount | tokenAmount(tokenInfo.decimals) }} / {{ maxPerAccountDailyWithdrawalAmount | tokenAmount(tokenInfo.decimals) }} {{ token }} @@ -116,7 +116,7 @@ export default class WithdrawForm extends Vue { amountIsValid: boolean = false isValidAddress: boolean = false recepient = "" - dailyRemainingWithdrawAmount: BN = ZERO + dailyRemainingWithdrawAmount: BN | null = null maxPerAccountDailyWithdrawalAmount: BN = ZERO tokenInfo: TokenData | null = null @@ -180,6 +180,7 @@ export default class WithdrawForm extends Vue { this.isValidAddress = false this.weiAmount = ZERO this.recepient = "" + this.dailyRemainingWithdrawAmount = null } isValidAddressFormat(isValid) { @@ -191,7 +192,9 @@ export default class WithdrawForm extends Vue { } get isWithdrawalLimitReached() { - return this.isWithdrawalLimitEnabled && this.dailyRemainingWithdrawAmount.lte(new BN(0)) + return this.isWithdrawalLimitEnabled + && this.dailyRemainingWithdrawAmount !== null + && this.dailyRemainingWithdrawAmount.lte(new BN(0)) } setAmountIsError(isError: boolean) {