Skip to content

Commit

Permalink
feat(delegated payments): extend turbo.getBalance method to include a…
Browse files Browse the repository at this point in the history
…pproval details PE-6754
  • Loading branch information
fedellen committed Oct 21, 2024
1 parent f2d26da commit baec107
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/common/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,15 @@ export class TurboUnauthenticatedPaymentService
allowedStatuses: [200, 404],
});

return balance.winc ? balance : { winc: '0' };
return balance.winc
? balance
: {
winc: '0',
controlledWinc: '0',
effectiveBalance: '0',
givenApprovals: [],
receivedApprovals: [],
};
}

public getFiatRates(): Promise<TurboRatesResponse> {
Expand Down
33 changes: 29 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,35 @@ export type TurboCheckoutSessionResponse = TurboWincForFiatResponse & {
paymentAmount: number;
};

export type TurboBalanceResponse = Omit<
TurboPriceResponse,
'adjustments' | 'fees'
>;
export interface DelegatedPaymentApproval {
approvalDataItemId: TransactionId;
approvedAddress: UserAddress;
payerAddress: UserAddress;
approvedWincAmount: string;
usedWincAmount: string;
creationDate: string;
expirationDate: string | undefined;
}

export type TurboBalanceResponse = {
/**
* Amount of winc controlled by the user, that they could
* spend or share if all current approvals were revoked
*/
controlledWinc: string;
/**
* Amount of winc that a user can currently spend or share
*/
winc: string;
/**
* Amount of winc that a user can currently spend or share
* plus the amount of remaining winc from received approvals
*/
effectiveBalance: string;

receivedApprovals: DelegatedPaymentApproval[];
givenApprovals: DelegatedPaymentApproval[];
};

export type TurboFiatToArResponse = {
currency: Currency;
Expand Down

0 comments on commit baec107

Please sign in to comment.