Skip to content

Commit

Permalink
Merge pull request #163 from ardriveapp/alpha
Browse files Browse the repository at this point in the history
chore: release v1.15.0
  • Loading branch information
fedellen authored Sep 12, 2024
2 parents f2e776a + 02b6c84 commit d90d6ed
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ardrive/turbo-sdk",
"version": "1.14.1",
"version": "1.15.0-alpha.2",
"main": "./lib/cjs/node/index.js",
"types": "./lib/types/node/index.d.ts",
"module": "./lib/esm/node/index.js",
Expand Down
23 changes: 15 additions & 8 deletions src/common/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,15 @@ export class TurboUnauthenticatedPaymentService

public getWincForFiat({
amount,
promoCodes = [],
nativeAddress = 'placeholder', // For price checks we only check promo code eligibility, a placeholder can be used
}: TurboWincForFiatParams): Promise<TurboWincForFiatResponse> {
const { amount: paymentAmount, type: currencyType } = amount;
return this.httpService.get<TurboWincForFiatResponse>({
endpoint: `/price/${currencyType}/${paymentAmount}`,
endpoint: `/price/${amount.type}/${
amount.amount
}?destinationAddress=${nativeAddress}&${this.appendPromoCodesToQuery(
promoCodes,
)}`,
});
}

Expand All @@ -156,7 +161,7 @@ export class TurboUnauthenticatedPaymentService
: ''
}&token=${this.token}`;

const { adjustments, paymentSession, topUpQuote } =
const { adjustments, paymentSession, topUpQuote, fees } =
await this.httpService.get<TopUpRawResponse>({
endpoint,
headers,
Expand All @@ -165,10 +170,13 @@ export class TurboUnauthenticatedPaymentService
return {
winc: topUpQuote.winstonCreditAmount,
adjustments,
fees,
url: paymentSession.url ?? undefined,
id: paymentSession.id,
client_secret: paymentSession.client_secret ?? undefined,
/** @deprecated -- backfilled for backwards compatibility, use actualPaymentAmount */
paymentAmount: topUpQuote.paymentAmount,
actualPaymentAmount: topUpQuote.paymentAmount,
quotedPaymentAmount: topUpQuote.quotedPaymentAmount,
};
}
Expand Down Expand Up @@ -252,11 +260,10 @@ export class TurboAuthenticatedPaymentService
amount,
promoCodes = [],
}: TurboWincForFiatParams): Promise<TurboWincForFiatResponse> {
return this.httpService.get<TurboWincForFiatResponse>({
endpoint: `/price/${amount.type}/${
amount.amount
}?${this.appendPromoCodesToQuery(promoCodes)}`,
headers: await this.signer.generateSignedRequestHeaders(),
return super.getWincForFiat({
amount,
promoCodes,
nativeAddress: await this.signer.getNativeAddress(),
});
}

Expand Down
19 changes: 17 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ export type CurrencyLimit = {
export type TurboPriceResponse = {
winc: string; // TODO: the service returns BigNumbers as strings
adjustments: Adjustment[];
fees: Adjustment[];
};

export type TurboWincForFiatResponse = TurboPriceResponse & {
paymentAmount: number;
actualPaymentAmount: number;
quotedPaymentAmount: number;
};

export type TurboWincForFiatParams = {
amount: CurrencyMap;
nativeAddress?: NativeAddress;
promoCodes?: string[];
};

Expand All @@ -96,25 +98,38 @@ export type TurboCheckoutSessionParams = TurboWincForFiatParams & {

export type TopUpRawResponse = {
topUpQuote: {
topUpQuoteId: string;
destinationAddressType: string;
paymentAmount: number;
quotedPaymentAmount: number;
winstonCreditAmount: string;
destinationAddress: string;
currencyType: Currency;
quoteExpirationDate: string;
paymentProvider: string;
adjustments: Adjustment[];
};
paymentSession: {
url: string | null;
id: string;
client_secret: string | null;
};
adjustments: Adjustment[];
fees: Adjustment[];
};

export type TurboCheckoutSessionResponse = TurboWincForFiatResponse & {
id: string;
client_secret?: string;
url?: string;
/** @deprecated use duplicate actualPaymentAmount */
paymentAmount: number;
};

export type TurboBalanceResponse = Omit<TurboPriceResponse, 'adjustments'>;
export type TurboBalanceResponse = Omit<
TurboPriceResponse,
'adjustments' | 'fees'
>;

export type TurboFiatToArResponse = {
currency: Currency;
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
*/

// AUTOMATICALLY GENERATED FILE - DO NOT TOUCH
export const version = '1.14.1';
export const version = '1.15.0-alpha.2';
12 changes: 11 additions & 1 deletion tests/turbo.node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,21 @@ describe('Node environment', () => {
});

it('getWincForFiat()', async () => {
const { winc } = await turbo.getWincForFiat({
const {
winc,
actualPaymentAmount,
adjustments,
quotedPaymentAmount,
fees,
} = await turbo.getWincForFiat({
amount: USD(10), // $10.00 USD
});
expect(winc).to.not.be.undefined;
expect(+winc).to.be.greaterThan(0);
expect(actualPaymentAmount).to.equal(1000);
expect(quotedPaymentAmount).to.equal(1000);
expect(adjustments).to.have.length(0);
expect(fees).to.have.length(1);
});

describe('uploadSignedDataItem()', () => {
Expand Down

0 comments on commit d90d6ed

Please sign in to comment.