From db9afb48553e7bedcb0eb199697c6a21098d3279 Mon Sep 17 00:00:00 2001 From: silverpill Date: Mon, 18 Jul 2022 20:39:26 +0000 Subject: [PATCH] Wait for sender balance update when paying for subscription --- src/api/subscriptions.ts | 2 +- src/components/Subscription.vue | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/api/subscriptions.ts b/src/api/subscriptions.ts index 82354c4..078bab4 100644 --- a/src/api/subscriptions.ts +++ b/src/api/subscriptions.ts @@ -14,7 +14,7 @@ const SECONDS_IN_MONTH = SECONDS_IN_DAY * 30 export interface SubscriptionToken { address: string; symbol: string; - decimals: string; + decimals: number; } export async function getSubscriptionToken( diff --git a/src/components/Subscription.vue b/src/components/Subscription.vue index 236c2a8..b03bf0e 100644 --- a/src/components/Subscription.vue +++ b/src/components/Subscription.vue @@ -252,7 +252,8 @@ async function onMakeSubscriptionPayment() { !instance?.blockchain_contract_address || !recipientEthereumAddress || !walletAddress || - !subscription + !subscription || + !subscriptionState ) { return } @@ -273,12 +274,18 @@ async function onMakeSubscriptionPayment() { return } await transaction.wait() - subscriptionState = await getSubscriptionState( - instance.blockchain_contract_address, - signer, - walletAddress, - recipientEthereumAddress, - ) + // Wait for sender balance update + // because JSON-RPC API can return outdated info on the first call + let newSubscriptionState + while (!newSubscriptionState || subscriptionState.senderBalance === newSubscriptionState.senderBalance) { + newSubscriptionState = await getSubscriptionState( + instance.blockchain_contract_address, + signer, + walletAddress, + recipientEthereumAddress, + ) + } + subscriptionState = newSubscriptionState tokenBalance = await getTokenBalance(signer, subscription.tokenAddress) isLoading = false }