From 23cf95b476bd86e4935599a6724de5529786f311 Mon Sep 17 00:00:00 2001 From: Jet Albano Date: Thu, 10 Oct 2024 16:22:30 +0800 Subject: [PATCH] Listened to first receiving address and changed address after successful payment --- src/components/MainFooter.vue | 17 ++++++++++++++++- src/pages/ReceivePage.vue | 10 +++++++--- src/stores/wallet.js | 24 +----------------------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/components/MainFooter.vue b/src/components/MainFooter.vue index 1bce43d..b7d3072 100644 --- a/src/components/MainFooter.vue +++ b/src/components/MainFooter.vue @@ -47,9 +47,10 @@ import { useWalletStore } from 'src/stores/wallet'; import { useQuasar } from 'quasar' import { useRouter } from 'vue-router' -import { defineComponent, computed } from 'vue' +import { defineComponent, computed, onMounted } from 'vue' import SetAmountFormDialog from 'src/components/SetAmountFormDialog.vue' +import { Wallet } from 'src/wallet' export default defineComponent({ @@ -61,6 +62,20 @@ export default defineComponent({ const selectedCurrency = computed(() => walletStore.preferences.selectedCurrency) + async function generateFirstReceivingAddress () { + const wallet = new Wallet({ + xPubKey: walletStore.xPubKey, + walletHash: walletStore.walletHash, + posId: walletStore.posId, + }) + const addressSet = await wallet.generateReceivingAddress(1, { skipSubscription: false }) + return addressSet.receiving + } + onMounted(async () => { + const firstReceivingAddress = await generateFirstReceivingAddress() + walletStore.$patch({ firstReceivingAddress }) + }) + function promptAmount () { $q.dialog({ component: SetAmountFormDialog, diff --git a/src/pages/ReceivePage.vue b/src/pages/ReceivePage.vue index ccd82f7..8d51ee5 100644 --- a/src/pages/ReceivePage.vue +++ b/src/pages/ReceivePage.vue @@ -419,7 +419,7 @@ export default defineComponent({ const expiryDuration = currencyRateUpdateRate / 1000 const expirationTimestamp = Math.floor(currentTimestamp + expiryDuration) const diffSeconds = networkTimeDiff.value ? networkTimeDiff.value / 1000 : 0 - const adjustedExpirationTimestamp = expirationTimestamp + diffSeconds + const adjustedExpirationTimestamp = expirationTimestamp + diffSeconds paymentUri += `&expires=${adjustedExpirationTimestamp}` } @@ -436,7 +436,8 @@ export default defineComponent({ const websocketUrl = `${process.env.WATCHTOWER_WEBSOCKET}/watch/bch` const merchantReceivingAddress = addressSet.value?.receiving const websocketInits = [ - merchantReceivingAddress + merchantReceivingAddress, + walletStore.firstReceivingAddress, ] .filter(Boolean) .map(address => { @@ -446,7 +447,9 @@ export default defineComponent({ } }) - const websockets = ref(websocketInits) + + const isZerothAddress = walletStore.firstReceivingAddress === merchantReceivingAddress + const websockets = ref(isZerothAddress ? websocketInits.slice(0,1) : websocketInits) const websocketsReady = computed(() => { const readySockets = websockets.value.filter((websocket) => websocket.instance?.readyState === 1) return readySockets.length === websockets.value.length @@ -479,6 +482,7 @@ export default defineComponent({ if (newVal) { closeWebsocket() stopQrExpirationCountdown() + addressesStore.dequeueAddress() setTimeout(() => triggerSecondConfetti.value = true, 1500) } }) diff --git a/src/stores/wallet.js b/src/stores/wallet.js index 452d554..3342128 100644 --- a/src/stores/wallet.js +++ b/src/stores/wallet.js @@ -6,7 +6,6 @@ import { sha256, decodePaymentUri, getPubkeyAt, - pubkeyToCashAddress, } from 'src/wallet/utils'; @@ -16,6 +15,7 @@ export const useWalletStore = defineStore('wallet', { walletHash: null, xPubKey: null, linkCode: null, + firstReceivingAddress: null, deviceInfo: { name: '', @@ -52,14 +52,6 @@ export const useWalletStore = defineStore('wallet', { country: '', longitude: null, latitude: null, - }, - vault: { - receiving: { - address: '', - pubkey: '', - }, - address: '', - tokenAddress: '', } }, @@ -225,8 +217,6 @@ export const useWalletStore = defineStore('wallet', { * @param {String} data.wallet_hash * @param {String} data.primary_contact_number * - * @param {String} data.receiving_pubkey - * * @param {Object} [data.location] * @param {String} data.location.landmark * @param {String} data.location.location @@ -235,10 +225,6 @@ export const useWalletStore = defineStore('wallet', { * @param {String} data.location.country * @param {String} data.location.longitude * @param {String} data.location.latitude - * - * @param {Object} [data.vault] - * @param {String} data.vault.address - * @param {String} data.vault.token_address */ setMerchantInfo(data) { const merchantInfo = { @@ -255,14 +241,6 @@ export const useWalletStore = defineStore('wallet', { longitude: data?.location?.longitude, latitude: data?.location?.latitude, }, - vault: { - receiving: { - address: pubkeyToCashAddress(data?.receiving_pubkey), - pubkey: data?.receiving_pubkey, - }, - address: data?.vault?.address, - tokenAddress: data?.vault?.token_address, - } } this.merchantInfo = merchantInfo