Skip to content

Commit

Permalink
chore: minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
aorumbayev committed Mar 18, 2024
1 parent fa24406 commit 339d2d6
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 57 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# [2.0.0-beta.10](https://github.com/subtopia-algo/subtopia-js-sdk/compare/v2.0.0-beta.9...v2.0.0-beta.10) (2024-03-17)
# [2.0.0-beta.10](https://github.com/subtopia-algo/subtopia-js-sdk/compare/v2.0.0-beta.9...v2.0.0-beta.10) (2024-03-18)

# [2.0.0-beta.10](https://github.com/subtopia-algo/subtopia-js-sdk/compare/v2.0.0-beta.9...v2.0.0-beta.10) (2024-03-18)

# [2.0.0-beta.9](https://github.com/subtopia-algo/subtopia-js-sdk/compare/v2.0.0-beta.8...v2.0.0-beta.9) (2024-03-17)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import {
ChainType,
SUBTOPIA_REGISTRY_ID
} from "subtopia-js-sdk";
// ... your code
// ... your code

const subtopiaClient = await SubtopiaClient.init({
algodClient: PUT_ALGOD_INSTANCE_HERE,
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"pre-commit": "npm run lint:scripts && npm run format:scripts && npm run test:integration && npm run build && npm run docs"
},
"peerDependencies": {
"@algorandfoundation/algokit-utils": "^5.0.0",
"@algorandfoundation/algokit-utils": "^5.0.1",
"algosdk": "^2.7.0"
},
"devDependencies": {
Expand Down
66 changes: 22 additions & 44 deletions src/clients/SubtopiaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import {
LockerType,
PriceNormalizationType,
ProductDiscountCreationParams,
ProductExtraParams,
ProductInitParams,
ProductLifecycleStateUpdate,
ProductState,
Expand Down Expand Up @@ -254,9 +253,7 @@ export class SubtopiaClient {
* @returns {Promise<{txID: string}>} A promise that resolves to an object containing the transaction ID.
*/
protected async updateLifecycle(
params: ProductLifecycleStateUpdate,

extraParams?: ProductExtraParams
params: ProductLifecycleStateUpdate
): Promise<{
txID: string;
}> {
Expand All @@ -276,8 +273,8 @@ export class SubtopiaClient {
returns: { type: "void" },
}),
methodArgs: [lifecycle],
sender: extraParams?.creator.addr ?? this.creator.addr,
signer: extraParams?.creator.signer ?? this.creator.signer,
sender: this.creator.addr,
signer: this.creator.signer,
suggestedParams: await getParamsWithFeeCount(this.algodClient, 1),
});

Expand All @@ -293,15 +290,6 @@ export class SubtopiaClient {
};
}

/**
* Updates the creator account for the SubtopiaClient instance.
* This method sets a new creator account, which is used for signing transactions.
* @param {TransactionSignerAccount} newCreator - The new creator account to be set.
*/
public updateCreator(newCreator: TransactionSignerAccount): void {
this.creator = newCreator;
}

/**
* This method is used to enable the application (updates the lifecycle).
* The method returns the transaction ID.
Expand Down Expand Up @@ -374,9 +362,7 @@ export class SubtopiaClient {
* It returns the platform fee as a number.
* @returns {Promise<number>} A promise that resolves to the platform fee.
*/
public async getSubscriptionPlatformFee(
extraParams?: ProductExtraParams
): Promise<number> {
public async getSubscriptionPlatformFee(): Promise<number> {
if (this.price === 0) {
return new Promise((resolve) => resolve(0));
}
Expand All @@ -397,8 +383,8 @@ export class SubtopiaClient {
returns: { type: "uint64" },
}),
methodArgs: [priceInCents],
sender: extraParams?.creator.addr ?? this.creator.addr,
signer: extraParams?.creator.signer ?? this.creator.signer,
sender: this.creator.addr,
signer: makeEmptyTransactionSigner(),
suggestedParams: await getParamsWithFeeCount(this.algodClient, 1),
});

Expand Down Expand Up @@ -446,9 +432,7 @@ export class SubtopiaClient {
* It accepts a duration object as an argument and returns a promise that resolves to a DiscountRecord.
* @returns {Promise<DiscountRecord>} A promise that resolves to the discount record.
*/
public async getDiscount(
extraParams?: ProductExtraParams
): Promise<DiscountRecord | undefined> {
public async getDiscount(): Promise<DiscountRecord | undefined> {
const getDiscountAtc = new AtomicTransactionComposer();
getDiscountAtc.addMethodCall({
appID: this.appID,
Expand All @@ -468,8 +452,8 @@ export class SubtopiaClient {
name: ENCODED_DISCOUNT_BOX_KEY,
},
],
sender: extraParams?.creator.addr ?? this.creator.addr,
signer: extraParams?.creator.signer ?? this.creator.signer,
sender: this.creator.addr,
signer: makeEmptyTransactionSigner(),
suggestedParams: await getParamsWithFeeCount(this.algodClient, 1),
});

Expand Down Expand Up @@ -519,10 +503,7 @@ export class SubtopiaClient {
* @param {ProductDiscountCreationParams} params - The parameters for creating a discount.
* @returns {Promise<{txID: string}>} A promise that resolves to an object containing the transaction ID.
*/
public async createDiscount(
params: ProductDiscountCreationParams,
extraParams?: ProductExtraParams
): Promise<{
public async createDiscount(params: ProductDiscountCreationParams): Promise<{
txID: string;
}> {
const {
Expand Down Expand Up @@ -572,12 +553,12 @@ export class SubtopiaClient {
expiresIn,
{
txn: makePaymentTxnWithSuggestedParamsFromObject({
from: extraParams?.creator.addr ?? this.creator.addr,
from: this.creator.addr,
to: this.appAddress,
amount: calculateProductDiscountBoxCreateMbr(),
suggestedParams: await getParamsWithFeeCount(this.algodClient, 0),
}),
signer: extraParams?.creator.signer ?? this.creator.signer,
signer: this.creator.signer,
},
],
boxes: [
Expand All @@ -586,8 +567,8 @@ export class SubtopiaClient {
name: ENCODED_DISCOUNT_BOX_KEY,
},
],
sender: extraParams?.creator.addr ?? this.creator.addr,
signer: extraParams?.creator.signer ?? this.creator.signer,
sender: this.creator.addr,
signer: this.creator.signer,
suggestedParams: await getParamsWithFeeCount(this.algodClient, 2),
});

Expand All @@ -608,7 +589,7 @@ export class SubtopiaClient {
* Removes active discount from a product contract if exists.
* @returns {Promise<{txID: string}>} A promise that resolves to an object containing the transaction ID.
*/
public async deleteDiscount(extraParams?: ProductExtraParams): Promise<{
public async deleteDiscount(): Promise<{
txID: string;
}> {
const deleteDiscountAtc = new AtomicTransactionComposer();
Expand All @@ -626,8 +607,8 @@ export class SubtopiaClient {
name: ENCODED_DISCOUNT_BOX_KEY,
},
],
sender: extraParams?.creator.addr ?? this.creator.addr,
signer: extraParams?.creator.signer ?? this.creator.signer,
sender: this.creator.addr,
signer: this.creator.signer,
suggestedParams: await getParamsWithFeeCount(this.algodClient, 2),
});

Expand Down Expand Up @@ -1021,9 +1002,7 @@ export class SubtopiaClient {
* @returns {Promise<boolean>} - A promise that resolves to a boolean indicating whether the address is a subscriber.
*/
public async isSubscriber(
params: ProductSubscriberCheckParams,

extraParams?: ProductExtraParams
params: ProductSubscriberCheckParams
): Promise<boolean> {
const { subscriberAddress } = params;
const isSubscriberAtc = new AtomicTransactionComposer();
Expand All @@ -1041,8 +1020,8 @@ export class SubtopiaClient {
returns: { type: "uint64" },
}),
methodArgs: [subscriberAddress],
sender: extraParams?.creator.addr ?? this.creator.addr,
signer: extraParams?.creator.signer ?? makeEmptyTransactionSigner(),
sender: this.creator.addr,
signer: makeEmptyTransactionSigner(),
boxes: [
{
appIndex: this.appID,
Expand Down Expand Up @@ -1081,8 +1060,7 @@ export class SubtopiaClient {
* @returns {Promise<SubscriptionRecord>} A promise that resolves to a SubscriptionRecord.
*/
public async getSubscription(
params: ProductSubscriptionRetrievalParams,
extraParams?: ProductExtraParams
params: ProductSubscriptionRetrievalParams
): Promise<SubscriptionRecord> {
const { algodClient, subscriberAddress } = params;
const getSubscriptionAtc = new AtomicTransactionComposer();
Expand All @@ -1100,7 +1078,7 @@ export class SubtopiaClient {
returns: { type: "(uint64,uint64,uint64,uint64,uint64)" },
}),
methodArgs: [subscriberAddress],
sender: extraParams?.creator.addr ?? this.creator.addr,
sender: this.creator.addr,
signer: makeEmptyTransactionSigner(),
boxes: [
{
Expand Down
4 changes: 0 additions & 4 deletions src/types/product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,3 @@ export interface ProductInitParams {
registryID?: number;
timeout?: number;
}
export interface ProductExtraParams {
creator: TransactionSignerAccount;
[key: string]: string | number | object;
}

0 comments on commit 339d2d6

Please sign in to comment.