Skip to content

Commit

Permalink
Merge pull request #52 from paytaca/improvements/payment-vault
Browse files Browse the repository at this point in the history
Listened to first receiving address and changed address after successful payment
  • Loading branch information
joemarct authored Oct 17, 2024
2 parents 3a63e36 + 23cf95b commit 80d4531
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
17 changes: 16 additions & 1 deletion src/components/MainFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions src/pages/ReceivePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
Expand All @@ -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 => {
Expand All @@ -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
Expand Down Expand Up @@ -479,6 +482,7 @@ export default defineComponent({
if (newVal) {
closeWebsocket()
stopQrExpirationCountdown()
addressesStore.dequeueAddress()
setTimeout(() => triggerSecondConfetti.value = true, 1500)
}
})
Expand Down
24 changes: 1 addition & 23 deletions src/stores/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
sha256,
decodePaymentUri,
getPubkeyAt,
pubkeyToCashAddress,
} from 'src/wallet/utils';


Expand All @@ -16,6 +15,7 @@ export const useWalletStore = defineStore('wallet', {
walletHash: null,
xPubKey: null,
linkCode: null,
firstReceivingAddress: null,

deviceInfo: {
name: '',
Expand Down Expand Up @@ -52,14 +52,6 @@ export const useWalletStore = defineStore('wallet', {
country: '',
longitude: null,
latitude: null,
},
vault: {
receiving: {
address: '',
pubkey: '',
},
address: '',
tokenAddress: '',
}
},

Expand Down Expand Up @@ -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
Expand All @@ -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 = {
Expand All @@ -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
Expand Down

0 comments on commit 80d4531

Please sign in to comment.