Skip to content

Commit

Permalink
chore: refining subscribe method
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Sep 24, 2023
1 parent a5e7e0e commit 0e62fbf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/clients/SubtopiaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,17 +584,18 @@ export class SubtopiaClient {
oracleAdminState.valueRaw
);
const platformFeeAmount = await this.getSubscriptionPlatformFee();
const creatorLockerId = await SubtopiaRegistryClient.getLocker({
const state = await this.getAppState(parseWholeUnits);
const managerLockerID = await SubtopiaRegistryClient.getLocker({
registryID: TESTNET_SUBTOPIA_REGISTRY_ID,
algodClient: this.algodClient,
ownerAddress: this.creator.addr,
ownerAddress: state.manager,
});

if (!creatorLockerId) {
if (!managerLockerID) {
throw new Error("Creator locker is not initialized");
}

const lockerAddress = getApplicationAddress(creatorLockerId);
const lockerAddress = getApplicationAddress(managerLockerID);

const createSubscriptionAtc = new AtomicTransactionComposer();
createSubscriptionAtc.addMethodCall({
Expand Down Expand Up @@ -643,7 +644,7 @@ export class SubtopiaClient {
methodArgs: [
subscriber.addr,
duration.valueOf(),
creatorLockerId,
managerLockerID,
this.oracleID,
{
txn: makePaymentTxnWithSuggestedParamsFromObject({
Expand Down
16 changes: 8 additions & 8 deletions src/clients/SubtopiaRegistryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,18 +331,18 @@ export class SubtopiaRegistryClient {
}): Promise<{
txID: string;
}> {
const oldOwnerLockerId = await SubtopiaRegistryClient.getLocker({
const oldOwnerLockerID = await SubtopiaRegistryClient.getLocker({
registryID: this.appID,
algodClient: this.algodClient,
ownerAddress: this.creator.addr,
});
const newOwnerLockerId = await SubtopiaRegistryClient.getLocker({
const newOwnerLockerID = await SubtopiaRegistryClient.getLocker({
registryID: this.appID,
algodClient: this.algodClient,
ownerAddress: newOwnerAddress,
});

if (!oldOwnerLockerId) {
if (!oldOwnerLockerID) {
throw new Error("Locker not found");
}

Expand All @@ -363,7 +363,7 @@ export class SubtopiaRegistryClient {
},
];

if (!newOwnerLockerId) {
if (!newOwnerLockerID) {
boxes.push.apply(boxes, [
{
appIndex: this.appID,
Expand Down Expand Up @@ -407,13 +407,13 @@ export class SubtopiaRegistryClient {
}),
methodArgs: [
infrastructureID,
oldOwnerLockerId,
oldOwnerLockerID,
newOwnerAddress,
{
txn: makePaymentTxnWithSuggestedParamsFromObject({
from: this.creator.addr,
to: this.appAddress,
amount: algosToMicroalgos(newOwnerLockerId ? 1 : 0.5),
amount: algosToMicroalgos(newOwnerLockerID ? 1 : 0.5),
suggestedParams: await getParamsWithFeeCount(this.algodClient, 0),
}),
signer: this.creator.signer,
Expand All @@ -422,10 +422,10 @@ export class SubtopiaRegistryClient {
boxes: boxes,
sender: this.creator.addr,
signer: this.creator.signer,
appForeignApps: newOwnerLockerId ? [newOwnerLockerId] : undefined,
appForeignApps: newOwnerLockerID ? [newOwnerLockerID] : undefined,
suggestedParams: await getParamsWithFeeCount(
this.algodClient,
newOwnerLockerId ? 10 : 11
newOwnerLockerID ? 10 : 11
),
});

Expand Down

0 comments on commit 0e62fbf

Please sign in to comment.