Skip to content

Commit

Permalink
fix(types): Payment listUserPaymentAccounts return response (#370)
Browse files Browse the repository at this point in the history
* fix(types): Payment listUserPaymentAccounts return response

* fix(types): Payment listUserPaymentAccounts return response

* Create chilly-pens-listen.md
  • Loading branch information
rrr523 authored Oct 16, 2023
1 parent dde423e commit 5c2d075
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/chilly-pens-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bnb-chain/greenfield-js-sdk": patch
---

fix(types): Payment listUserPaymentAccounts return response
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EMPTY_STRING_SHA256, METHOD_GET } from '@/constants';
import { ReqMeta } from '@/types';
import { convertStrToBool } from '@/types/sp/Common';
import {
ListUserPaymentAccountsResponse,
ListUserPaymentAccountsResquest,
Expand Down Expand Up @@ -47,15 +48,27 @@ export const parseListUserPaymentAccountResponse = (data: string) => {
});
const res = xmlParser.parse(data) as ListUserPaymentAccountsResponse;

let StreamRecords = res.GfSpListUserPaymentAccountsResponse.StreamRecords || [];
let PaymentAccounts = res.GfSpListUserPaymentAccountsResponse.PaymentAccounts || [];

if (StreamRecords) {
if (!Array.isArray(StreamRecords)) {
StreamRecords = [StreamRecords];
if (PaymentAccounts) {
if (!Array.isArray(PaymentAccounts)) {
PaymentAccounts = [PaymentAccounts];
}

PaymentAccounts = PaymentAccounts.map((item) => {
item.PaymentAccount = {
...item.PaymentAccount,
// @ts-ignore
Refundable: convertStrToBool(item.PaymentAccount.Refundable),
UpdateAt: Number(item.PaymentAccount.UpdateAt),
UpdateTime: Number(item.PaymentAccount.UpdateTime),
};

return item;
});
}

res.GfSpListUserPaymentAccountsResponse.StreamRecords = StreamRecords;
res.GfSpListUserPaymentAccountsResponse.PaymentAccounts = PaymentAccounts;

return res;
};
18 changes: 12 additions & 6 deletions packages/js-sdk/src/types/sp/ListUserPaymentAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,17 @@ export type ListUserPaymentAccountsResponse = {
GfSpListUserPaymentAccountsResponse: GfSPListUserPaymentAccountsResponse;
};

export interface GfSPListUserPaymentAccountsResponse {
StreamRecords: StreamRecords[];
}
export type PaymentAccount = {
Address: string;
Owner: string;
Refundable: boolean;
UpdateAt: number;
UpdateTime: number;
};

export interface StreamRecords {
StreamRecord: StreamRecord;
Refundable: string;
export interface GfSPListUserPaymentAccountsResponse {
PaymentAccounts: {
PaymentAccount: PaymentAccount;
StreamRecord: StreamRecord;
}[];
}

0 comments on commit 5c2d075

Please sign in to comment.