Skip to content

Commit b8636c2

Browse files
committed
Reset estimate when modal is closed, using a composable
1 parent 44258b4 commit b8636c2

File tree

5 files changed

+19
-16
lines changed

5 files changed

+19
-16
lines changed

src/components/modals/BuyCryptoModal.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
</template>
256256

257257
<script lang="ts">
258-
import { defineComponent, ref, computed, watch, onMounted, onUnmounted } from '@vue/composition-api';
258+
import { defineComponent, ref, computed, watch, onMounted } from '@vue/composition-api';
259259
import {
260260
PageHeader,
261261
PageBody,
@@ -331,7 +331,7 @@ import {
331331
capDecimals,
332332
currentLimitCrypto,
333333
currentLimitFiat,
334-
estimate,
334+
useSwapEstimate,
335335
eurPerBtc,
336336
eurPerNim,
337337
fetchAssets,
@@ -361,6 +361,7 @@ export default defineComponent({
361361
362362
const { width } = useWindowSize();
363363
const { limits } = useSwapLimits({ nimAddress: activeAddress.value! });
364+
const { estimate } = useSwapEstimate();
364365
365366
const $eurAmountInput = ref<typeof AmountInput & { focus(): void } | null>(null);
366367
@@ -911,10 +912,6 @@ export default defineComponent({
911912
fiatAmount.value = (currentLimitFiat.value || 0) * 1e2;
912913
}
913914
914-
onUnmounted(() => {
915-
estimate.value = null;
916-
});
917-
918915
return {
919916
$eurAmountInput,
920917
addressListOpened,

src/components/modals/SellCryptoModal.vue

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@
285285
</template>
286286

287287
<script lang="ts">
288-
import { defineComponent, ref, computed, watch, onMounted, onUnmounted } from '@vue/composition-api';
288+
import { defineComponent, ref, computed, watch, onMounted } from '@vue/composition-api';
289289
import {
290290
PageHeader,
291291
PageBody,
@@ -356,7 +356,7 @@ import {
356356
capDecimals,
357357
currentLimitCrypto,
358358
currentLimitFiat,
359-
estimate,
359+
useSwapEstimate,
360360
eurPerBtc,
361361
eurPerNim,
362362
fetchAssets,
@@ -396,6 +396,7 @@ export default defineComponent({
396396
const { width } = useWindowSize();
397397
const { limits } = useSwapLimits({ nimAddress: activeAddress.value! });
398398
const { trials } = useSettingsStore();
399+
const { estimate } = useSwapEstimate();
399400
400401
const $cryptoAmountInput = ref<typeof AmountInput & { focus(): void } | null>(null);
401402
@@ -997,10 +998,6 @@ export default defineComponent({
997998
}
998999
}
9991000
1000-
onUnmounted(() => {
1001-
estimate.value = null;
1002-
});
1003-
10041001
return {
10051002
$cryptoAmountInput,
10061003
addressListOpened,

src/lib/swap/utils/BuyUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import {
1212
HtlcStatus,
1313
} from '../../OasisApi';
1414
import { i18n } from '../../../i18n/i18n-setup';
15-
import { calculateFees, estimate, getFiatSwapParameters, selectedFiatCurrency } from './CommonUtils';
15+
import { calculateFees, getFiatSwapParameters, selectedFiatCurrency, useSwapEstimate } from './CommonUtils';
1616

1717
const { activeSwap: swap } = useSwapsStore();
1818
const { exchangeRates } = useFiatStore();
1919
const { activeCurrency } = useAccountStore();
20-
20+
const { estimate } = useSwapEstimate();
2121
/**
2222
* Buy - Buy crypto related things
2323
* - Computeds

src/lib/swap/utils/CommonUtils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { AssetList, Estimate, getAssets, RequestAsset, SwapAsset } from '@nimiq/fastspot-api';
22
import { CurrencyInfo } from '@nimiq/utils';
3-
import { computed, ref } from '@vue/composition-api';
3+
import { computed, onUnmounted, ref, getCurrentInstance } from '@vue/composition-api';
44
import { useSwapLimits } from '../../../composables/useSwapLimits';
55
import { useAccountStore } from '../../../stores/Account';
66
import { useAddressStore } from '../../../stores/Address';
@@ -277,3 +277,11 @@ export function getFiatSwapParameters({ from, to } : {
277277

278278
return { from: null, to: null };
279279
}
280+
281+
export function useSwapEstimate() {
282+
if (getCurrentInstance()) {
283+
onUnmounted(() => estimate.value = null);
284+
}
285+
286+
return { estimate };
287+
}

src/lib/swap/utils/SellUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import {
1414
import { estimateFees } from '../../BitcoinTransactionUtils';
1515
import { useBtcAddressStore } from '../../../stores/BtcAddress';
1616
import { i18n } from '../../../i18n/i18n-setup';
17-
import { assets, calculateFees, estimate, getFiatSwapParameters, selectedFiatCurrency } from './CommonUtils';
17+
import { assets, calculateFees, getFiatSwapParameters, selectedFiatCurrency, useSwapEstimate } from './CommonUtils';
1818

1919
const { activeSwap: swap } = useSwapsStore();
2020
const { exchangeRates } = useFiatStore();
2121
const { activeCurrency } = useAccountStore();
2222
const { accountBalance: accountBtcBalance, accountUtxos } = useBtcAddressStore();
23+
const { estimate } = useSwapEstimate();
2324

2425
/**
2526
* Sell - Sell crypto related things

0 commit comments

Comments
 (0)