Skip to content

Commit 58dd7fb

Browse files
committed
fix: not show countdown for grecaptcha while a transaction is being processed
1 parent 769b6ef commit 58dd7fb

File tree

13 files changed

+44
-12
lines changed

13 files changed

+44
-12
lines changed

.env.local.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ VUE_APP_LBC_ADDRESS='0xc2A630c053D12D63d32b025082f6Ba268db18300'
2727
VUE_APP_DEBUG_MODE='true'
2828

2929
NODE_ENV=test
30-
VUE_APP_FLYOVER_PEGOUT_QUOTE_DIFF_PERCENTAGE=2 # 2%
30+
VUE_APP_FLYOVER_PEGOUT_QUOTE_DIFF_PERCENTAGE=2
31+
VUE_APP_RECAPTCHA_NEW_TOKEN_TIME=30
3132

.github/workflows/deploy_MainNet_UI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
VUE_APP_SLOW_MINING_BLOCK=5
5555
VUE_APP_LBC_ADDRESS='0xAA9cAf1e3967600578727F975F283446A3Da6612'
5656
VUE_APP_FLYOVER_PEGOUT_QUOTE_DIFF_PERCENTAGE=2
57+
VUE_APP_RECAPTCHA_NEW_TOKEN_TIME=30
5758
npm run-script build
5859
5960
- name: Configure AWS credentials

.github/workflows/deploy_TestNet_UI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
VUE_APP_SLOW_MINING_BLOCK=5
5555
VUE_APP_LBC_ADDRESS='0xc2A630c053D12D63d32b025082f6Ba268db18300'
5656
VUE_APP_FLYOVER_PEGOUT_QUOTE_DIFF_PERCENTAGE=2
57+
VUE_APP_RECAPTCHA_NEW_TOKEN_TIME=30
5758
npm run-script build
5859
5960
- name: Configure AWS credentials

.github/workflows/deploy_staging_MainNet_UI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
VUE_APP_SLOW_MINING_BLOCK=5
5555
VUE_APP_LBC_ADDRESS='0xAA9cAf1e3967600578727F975F283446A3Da6612'
5656
VUE_APP_FLYOVER_PEGOUT_QUOTE_DIFF_PERCENTAGE=2
57+
VUE_APP_RECAPTCHA_NEW_TOKEN_TIME=30
5758
npm run-script build
5859
5960
- name: Configure AWS credentials

.github/workflows/deploy_staging_TestNet_UI.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ jobs:
5454
VUE_APP_SLOW_MINING_BLOCK=5
5555
VUE_APP_LBC_ADDRESS='0xc2A630c053D12D63d32b025082f6Ba268db18300'
5656
VUE_APP_FLYOVER_PEGOUT_QUOTE_DIFF_PERCENTAGE=20
57+
VUE_APP_RECAPTCHA_NEW_TOKEN_TIME=30
5758
npm run-script build
5859
5960
- name: Configure AWS credentials

ENV_VARIABLES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The value of these variables are used in **environment-variables.ts** file.
2222
|VUE_APP_LBC_ADDRESS | `0xc2A630c053D12D63d32b025082f6Ba268db18300` | Liquidity bridge contract address on the flyover protocol |
2323
|VUE_APP_DEBUG_MODE | `false` | enable developer messages for debuging |
2424
|VUE_APP_FLYOVER_PEGOUT_QUOTE_DIFF_PERCENTAGE | `2` | Defines quote difference percentage to 2% so it requieres the user to review condition only for a difference bigger that this percentage |
25+
|VUE_APP_RECAPTCHA_NEW_TOKEN_TIME | `30` | Specifies the time (in seconds) to temporarily disable the flyover between new transactions. This accounts for the time required by Google reCAPTCHA to regenerate a challenge token |
2526

2627
## Example for .env.local.test file
2728

src/common/store/session/mutations.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TransactionType, SessionState } from '@/common/types/session';
55
import { getClearSessionState } from '@/common/utils';
66
import { providers } from 'ethers';
77
import i18n from '@/i18n';
8+
import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service';
89

910
export const mutations: MutationTree<SessionState> = {
1011
[constants.SESSION_SET_ACCOUNT]: (state, account: string) => {
@@ -58,7 +59,8 @@ export const mutations: MutationTree<SessionState> = {
5859
state.apiVersion = apiVersion;
5960
},
6061
[constants.SESSION_RESET_GRECAPTCHA_COUNTDOWN]: (state) => {
61-
state.grecaptchaCountdown = constants.RECAPTCHA_NEW_TOKEN_TIME;
62+
state.grecaptchaCountdown = EnvironmentAccessorService.getEnvironmentVariables()
63+
.grecaptchaTime;
6264
},
6365
[constants.SESSION_SET_DECREMENT_GRECAPTCHA_COUNTDOWN]: (state) => {
6466
if (state.grecaptchaCountdown > 0) {

src/common/types/environment-variables.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export class EnvironmentVariables {
5050

5151
public flyoverPegoutDiffPercentage: number;
5252

53+
public grecaptchaTime: number;
54+
5355
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5456
constructor(defaultValues: any = {}) {
5557
this.vueAppCoin = process.env.VUE_APP_COIN || defaultValues.vueAppCoin;
@@ -96,6 +98,8 @@ export class EnvironmentVariables {
9698
|| defaultValues.flyoverGetProvidersTimeout;
9799
this.flyoverPegoutDiffPercentage = Number(process.env
98100
.VUE_APP_FLYOVER_PEGOUT_QUOTE_DIFF_PERCENTAGE) || defaultValues.flyoverPegoutDiffPercentage;
101+
this.grecaptchaTime = Number(process.env.VUE_APP_RECAPTCHA_NEW_TOKEN_TIME)
102+
|| defaultValues.grecaptchaTime;
99103
}
100104

101105
public get chainId(): number {

src/common/utils/common.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
import { FlyoverService } from '@/common/services';
1010
import { markRaw } from 'vue';
1111
import * as constants from '@/common/store/constants';
12+
import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service';
1213

1314
export const getChunkedValue = (value: string, maxLength: number) => (value.length < maxLength ? value : `${value.substr(0, maxLength / 2)}...${value.substr(value.length - maxLength / 2, value.length)}`);
1415

@@ -83,7 +84,7 @@ export const getClearPegoutTxState = (): PegOutTxState => ({
8384
selectedFee: BITCOIN_AVERAGE_FEE_LEVEL,
8485
});
8586

86-
export const getClearSessionState = ():SessionState => (
87+
export const getClearSessionState = (): SessionState => (
8788
{
8889
account: undefined,
8990
ethersProvider: undefined,
@@ -96,7 +97,8 @@ export const getClearSessionState = ():SessionState => (
9697
bitcoinPrice: 0,
9798
features: [],
9899
apiVersion: '',
99-
grecaptchaCountdown: constants.RECAPTCHA_NEW_TOKEN_TIME,
100+
grecaptchaCountdown: EnvironmentAccessorService.getEnvironmentVariables().grecaptchaTime
101+
?? constants.RECAPTCHA_NEW_TOKEN_TIME,
100102
grecaptchaIntervalId: undefined,
101103
}
102104
);

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const defaultEnvironmentVariables = {
3232
burnDustValue: 2000,
3333
flyoverGetProvidersTimeout: 5000,
3434
flyoverPegoutDiffPercentage: 2,
35+
grecaptchaTime: constants.RECAPTCHA_NEW_TOKEN_TIME,
3536
};
3637

3738
EnvironmentAccessorService.initializeEnvironmentVariables(defaultEnvironmentVariables);

src/pegin/components/create/PegInForm.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ import { FlyoverService } from '@/common/services';
107107
import FullTxErrorDialog from '@/common/components/exchange/FullTxErrorDialog.vue';
108108
import RskDestinationAddress from '@/pegin/components/create/RskDestinationAddress.vue';
109109
import { AcceptedQuote } from '@rsksmart/flyover-sdk';
110+
import { EnvironmentAccessorService } from '@/common/services/enviroment-accessor.service';
110111
111112
export default defineComponent({
112113
name: 'PegInForm',
@@ -152,6 +153,8 @@ export default defineComponent({
152153
const loadingFee = useStateAttribute<boolean>('pegInTx', 'loadingFee');
153154
const startCountdown = useAction('web3Session', constants.SESSION_COUNTDOWN_GRECAPTCHA_TIME);
154155
const countdown = useStateAttribute<number>('web3Session', 'grecaptchaCountdown');
156+
const recaptchanNewTokenTime = EnvironmentAccessorService.getEnvironmentVariables()
157+
.grecaptchaTime;
155158
156159
const enoughAmountFlyover = computed(() => {
157160
if (!selectedQuote.value) {
@@ -161,6 +164,8 @@ export default defineComponent({
161164
return selectedAccountBalance.value?.gte(fullAmount);
162165
});
163166
167+
const sendingPegin = computed(():boolean => pegInFormState.value.matches(['loading']));
168+
164169
const peginQuotes = computed(() => {
165170
if (!props.isFlyoverAvailable) {
166171
return [];
@@ -174,8 +179,13 @@ export default defineComponent({
174179
return quoteList;
175180
});
176181
177-
const flyoverIsEnabled = computed(() => props.isFlyoverAvailable
178-
&& countdown.value === constants.RECAPTCHA_NEW_TOKEN_TIME);
182+
const flyoverIsEnabled = computed(() => {
183+
if (props.isFlyoverAvailable) {
184+
if (sendingPegin.value) return true;
185+
return countdown.value === recaptchanNewTokenTime;
186+
}
187+
return false;
188+
});
179189
180190
function back() {
181191
pegInFormState.value.send('loading');
@@ -300,7 +310,7 @@ export default defineComponent({
300310
&& !!flyoverPeginState.value.selectedQuoteHash
301311
&& !!flyoverPeginState.value.rootstockRecipientAddress
302312
&& flyoverPeginState.value.rootstockRecipientAddress !== '0x'
303-
&& countdown.value === constants.RECAPTCHA_NEW_TOKEN_TIME;
313+
&& countdown.value === recaptchanNewTokenTime;
304314
}
305315
306316
return false;
@@ -358,7 +368,7 @@ export default defineComponent({
358368
sendTx,
359369
flyoverIsEnabled,
360370
countdown,
361-
recaptchanNewTokenTime: constants.RECAPTCHA_NEW_TOKEN_TIME,
371+
recaptchanNewTokenTime,
362372
};
363373
},
364374
});

src/pegout/components/PegoutForm.vue

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ export default defineComponent({
213213
const liquidityProviders = useStateAttribute<LiquidityProvider2WP[]>('flyoverPegout', 'liquidityProviders');
214214
const startCountdown = useAction('web3Session', constants.SESSION_COUNTDOWN_GRECAPTCHA_TIME);
215215
const countdown = useStateAttribute<number>('web3Session', 'grecaptchaCountdown');
216+
const recaptchanNewTokenTime = EnvironmentAccessorService.getEnvironmentVariables()
217+
.grecaptchaTime;
216218
217219
const pegoutQuotes = computed(() => {
218220
const quoteList: QuotePegOut2WP[] = [];
@@ -305,11 +307,16 @@ export default defineComponent({
305307
const isValid = computed(() => {
306308
if (selectedQuote.value === undefined) return !loadingQuotes.value && isReadyToCreate.value;
307309
return !loadingQuotes.value && isFlyoverReady.value
308-
&& countdown.value === constants.RECAPTCHA_NEW_TOKEN_TIME;
310+
&& countdown.value === recaptchanNewTokenTime;
311+
});
312+
313+
const showCountdown = computed(() => {
314+
if (sendingPegout.value) return true;
315+
return countdown.value === recaptchanNewTokenTime;
309316
});
310317
311318
const flyoverIsEnabled = computed(() => pegoutQuotes.value.length > 0
312-
&& props.flyoverEnabled && countdown.value === constants.RECAPTCHA_NEW_TOKEN_TIME);
319+
&& props.flyoverEnabled && showCountdown.value);
313320
314321
function handlePegoutError(error: ServiceError) {
315322
txError.value = error;
@@ -569,7 +576,7 @@ export default defineComponent({
569576
clearAmount,
570577
checkValidAmount,
571578
countdown,
572-
recaptchanNewTokenTime: constants.RECAPTCHA_NEW_TOKEN_TIME,
579+
recaptchanNewTokenTime,
573580
};
574581
},
575582
});

src/pegout/components/PegoutOption.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<v-card :ripple="false" rounded="lg" flat variant="outlined"
3-
@click="selectOption" height="400px" :disabled="flyoverNotAvailable"
3+
@click="selectOption" :disabled="flyoverNotAvailable"
44
:class="{ 'selected': selectedOption, 'not-available': flyoverNotAvailable }"
55
class="pa-8">
66
<div v-if="flyoverNotAvailable"

0 commit comments

Comments
 (0)