Skip to content

Commit

Permalink
fix: bug fixing the renewal flow (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev authored Dec 13, 2023
1 parent a987ae6 commit c04285b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"start": "vite --host --open",
"build": "tsc && vite build && dts-bundle-generator --config ./dts-bundle-generator.config.ts",
"watch": "tsc && vite build --watch",
"test": "vitest run",
"test:integration": "vitest run --coverage",
"localnet:start": "pipx run algokit localnet start",
"localnet:stop": "pipx run algokit localnet start",
Expand Down
20 changes: 17 additions & 3 deletions src/clients/SubtopiaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,19 @@ export class SubtopiaClient {
}
}

const currentSubscription = await this.getSubscription({
algodClient: this.algodClient,
subscriberAddress: subscriber.addr,
}).catch(() => {
return null;
});
const isHoldingSubscription = currentSubscription !== null;
const isActiveSubscriber = await this.isSubscriber({
subscriberAddress: subscriber.addr,
});
const isHoldingExpiredSubscription =
isHoldingSubscription && !isActiveSubscriber;

const createSubscriptionAtc = new AtomicTransactionComposer();
createSubscriptionAtc.addMethodCall({
appID: this.appID,
Expand Down Expand Up @@ -791,9 +804,10 @@ export class SubtopiaClient {
txn: makePaymentTxnWithSuggestedParamsFromObject({
from: subscriber.addr,
to: this.appAddress,
amount:
calculateProductSubscriptionBoxCreateMbr(subscriber.addr) +
algosToMicroalgos(MIN_ASA_CREATE_MBR),
amount: isHoldingExpiredSubscription
? 0
: calculateProductSubscriptionBoxCreateMbr(subscriber.addr) +
algosToMicroalgos(MIN_ASA_CREATE_MBR),
suggestedParams: await getParamsWithFeeCount(this.algodClient, 0),
}),
signer: subscriber.signer,
Expand Down

0 comments on commit c04285b

Please sign in to comment.