Skip to content

Commit

Permalink
fix: review conditions only if differnece is bigger than 2%
Browse files Browse the repository at this point in the history
  • Loading branch information
annipi committed Nov 20, 2024
1 parent 4cea871 commit 750e942
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
23 changes: 13 additions & 10 deletions src/pegout/components/PegoutForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@

<script lang="ts">
import {
computed, defineComponent, onBeforeMount, ref, watch,
computed, defineComponent, onBeforeMount, onMounted, ref, watch,
} from 'vue';
import * as constants from '@/common/store/constants';
import EnvironmentContextProviderService from '@/common/providers/EnvironmentContextProvider';
Expand Down Expand Up @@ -196,7 +196,8 @@ export default defineComponent({
const isTrezorConnected = useGetter<boolean>('web3Session', constants.SESSION_IS_TREZOR_CONNECTED);
const isMetamaskConnected = useGetter<boolean>('web3Session', constants.SESSION_IS_METAMASK_CONNECTED);
const setSelectedQuoteHash = useAction('flyoverPegout', constants.FLYOVER_PEGOUT_SET_SELECTED_QUOTE_HASH);
const selectedOption = ref<string | undefined>('');
const selectedQuoteHash = useStateAttribute<string>('flyoverPegout', 'selectedQuoteHash');
const selectedOption = ref<string>('');
const quoteDiffPercentage = EnvironmentAccessorService.getEnvironmentVariables()
.flyoverPegoutDiffPercentage;
Expand Down Expand Up @@ -233,7 +234,7 @@ export default defineComponent({
const isReadyToCreate = computed((): boolean => isEnoughBalance.value
&& !!account.value
&& validAmountToReceive.value
&& selectedOption.value !== undefined);
&& selectedOption.value === '');
const isFlyoverReady = computed(() => {
if (selectedOption.value && selectedQuote.value) {
Expand Down Expand Up @@ -282,7 +283,7 @@ export default defineComponent({
}));
const isValid = computed(() => {
if (selectedOption.value === '') return isReadyToCreate.value;
if (selectedQuote.value === undefined) return isReadyToCreate.value;
return isFlyoverReady.value;
});
Expand Down Expand Up @@ -347,7 +348,7 @@ export default defineComponent({
async function send() {
clearAmount.value = false;
const quoteHash = selectedOption.value;
const quoteHash = selectedQuoteHash.value || '';
const type = quoteHash
? TxStatusType.FLYOVER_PEGOUT.toLowerCase()
: TxStatusType.PEGOUT.toLowerCase();
Expand Down Expand Up @@ -404,7 +405,7 @@ export default defineComponent({
}
function executeRecaptcha() {
if (!window.grecaptcha.getResponse()) {
if (selectedQuoteHash.value) {
window.grecaptcha.execute();
} else {
send();
Expand All @@ -417,7 +418,7 @@ export default defineComponent({
function continueHandler() {
setSelectedQuoteHash('');
selectedOption.value = undefined;
selectedOption.value = '';
diffShown.value = false;
}
Expand All @@ -433,9 +434,11 @@ export default defineComponent({
}
});
if (props.flyoverEnabled) {
appendRecaptcha(flyoverService.value.siteKey);
}
onMounted(() => {
if (props.flyoverEnabled) {
appendRecaptcha(flyoverService.value.siteKey);
}
});
watch(account, clearState);
Expand Down
6 changes: 3 additions & 3 deletions src/pegout/components/RbtcInputAmount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,6 @@ export default defineComponent({
|| safeAmount.value.lt(minValue);
});
const clearProp = computed(() => props.clear);
function blockLetterKeyDown(e: KeyboardEvent) {
const allowedKeys = ['Backspace', 'Delete', 'Home', 'End', 'ArrowRight', 'ArrowLeft'];
if (allowedKeys.includes(e.key)) return;
Expand Down Expand Up @@ -187,7 +185,9 @@ export default defineComponent({
}
watch(account, clearInput);
watch(clearProp, clearInput);
watch(() => props.clear, (flag) => {
if (flag) clearInput();
});
return {
amountStyle,
Expand Down
9 changes: 6 additions & 3 deletions src/pegout/store/FlyoverPegout/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,14 @@ export const actions: ActionTree<FlyoverPegoutState, RootState> = {
const minor = newQuoteTotalFee
.gt(currentQuoteTotalFee) ? currentQuoteTotalFee : newQuoteTotalFee;
const difference = ((largest.minus(minor)).mul('100')).div(largest.toRBTCString());
if (+difference.toRBTCString() <= EnvironmentAccessorService.getEnvironmentVariables()
.flyoverPegoutDiffPercentage) {
if (Number(difference.toRBTCString()) <= EnvironmentAccessorService
.getEnvironmentVariables().flyoverPegoutDiffPercentage) {
commit(constants.FLYOVER_PEGOUT_SET_SELECTED_QUOTE, quote2wp.quoteHash);
} else {
commit(constants.FLYOVER_PEGOUT_SET_QUOTES_DIFFERENCE, +difference.toRBTCString());
commit(
constants.FLYOVER_PEGOUT_SET_QUOTES_DIFFERENCE,
Number(difference.toRBTCString()),
);
}
});
resolve();
Expand Down

0 comments on commit 750e942

Please sign in to comment.