Skip to content

Commit

Permalink
feat: add txhash in request-client.js (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindavee authored Oct 13, 2021
1 parent 4cc80d7 commit c670a38
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/request-client.js/src/api/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,14 @@ export default class Request {
* @param amount Amount received
* @param note Note from payee about the received payment
* @param signerIdentity Identity of the signer. The identity type must be supported by the signature provider.
* @param txHash transaction hash
* @returns The updated request
*/
public async declareReceivedPayment(
amount: RequestLogicTypes.Amount,
note: string,
signerIdentity: IdentityTypes.IIdentity,
txHash?: string,
): Promise<Types.IRequestDataWithEvents> {
const extensionsData: any[] = [];

Expand All @@ -579,6 +581,7 @@ export default class Request {
declarativePaymentNetwork.createExtensionsDataForDeclareReceivedPayment({
amount,
note,
txHash,
}),
);

Expand Down Expand Up @@ -616,12 +619,14 @@ export default class Request {
* @param amount Amount received
* @param note Note from payer about the received refund
* @param signerIdentity Identity of the signer. The identity type must be supported by the signature provider.
* @param txHash transaction hash
* @returns The updated request
*/
public async declareReceivedRefund(
amount: RequestLogicTypes.Amount,
note: string,
signerIdentity: IdentityTypes.IIdentity,
txHash?: string,
): Promise<Types.IRequestDataWithEvents> {
const extensionsData: any[] = [];

Expand All @@ -641,6 +646,7 @@ export default class Request {
declarativePaymentNetwork.createExtensionsDataForDeclareReceivedRefund({
amount,
note,
txHash,
}),
);

Expand Down
46 changes: 46 additions & 0 deletions packages/request-client.js/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,29 @@ describe('index', () => {
expect(requestData.balance!.balance).toEqual('10');
});

it('allows to declare a received payment by providing transaction hash', async () => {
const requestNetwork = new RequestNetwork({ signatureProvider: fakeSignatureProvider });

const paymentNetwork: PaymentTypes.IPaymentNetworkCreateParameters = {
id: PaymentTypes.PAYMENT_NETWORK_ID.DECLARATIVE,
parameters: {},
};

const request = await requestNetwork.createRequest({
paymentNetwork,
requestInfo: TestData.parametersWithoutExtensionsData,
signer: payeeIdentity,
});
await request.waitForConfirmation();

mock.resetHistory();

await request.declareReceivedPayment('10', 'received payment', payeeIdentity, '0x123456789');

expect(mock.history.get).toHaveLength(4);
expect(mock.history.post).toHaveLength(1);
});

it('allows to declare a sent refund', async () => {
const requestNetwork = new RequestNetwork({ signatureProvider: fakeSignatureProvider });

Expand Down Expand Up @@ -925,6 +948,29 @@ describe('index', () => {
expect(requestData.balance!.balance).toEqual('-11');
});

it('allows to declare a received refund by providing transaction hash', async () => {
const requestNetwork = new RequestNetwork({ signatureProvider: fakeSignatureProvider });

const paymentNetwork: PaymentTypes.IPaymentNetworkCreateParameters = {
id: PaymentTypes.PAYMENT_NETWORK_ID.DECLARATIVE,
parameters: {},
};

const request = await requestNetwork.createRequest({
paymentNetwork,
requestInfo: TestData.parametersWithoutExtensionsData,
signer: payeeIdentity,
});
await request.waitForConfirmation();

mock.resetHistory();

await request.declareReceivedRefund('10', 'received refund', payerIdentity, '0x123456789');

expect(mock.history.get).toHaveLength(4);
expect(mock.history.post).toHaveLength(1);
});

it('allows to get the right balance', async () => {
const requestParametersUSD: RequestLogicTypes.ICreateParameters = {
currency: {
Expand Down

0 comments on commit c670a38

Please sign in to comment.