Skip to content

Commit

Permalink
[api] Update voucher details. Release 0.36.1 (#1476)
Browse files Browse the repository at this point in the history
  • Loading branch information
osipov-mit authored Jan 23, 2024
1 parent 052dff3 commit 4d33de1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
8 changes: 8 additions & 0 deletions api/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.36.1

_01/23/2024_

### Changes
https://github.com/gear-tech/gear-js/pull/1476
- Add `codeUploadin` field to `VoucherDetails`

## 0.36.0

_01/23/2024_
Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gear-js/api",
"version": "0.36.0",
"version": "0.36.1",
"description": "A JavaScript library that provides functionality to connect GEAR Component APIs.",
"main": "cjs/index.js",
"module": "index.js",
Expand Down
5 changes: 3 additions & 2 deletions api/src/Voucher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class GearVoucher extends GearTransaction {
*/
async issue(
spender: HexString,
value: number | bigint | BalanceOf,
value: number | bigint | BalanceOf | string,
duration?: number,
programs?: HexString[],
codeUploading = false,
Expand Down Expand Up @@ -290,12 +290,13 @@ export class GearVoucher extends GearTransaction {
return null;
}

const { owner, programs, expiry } = voucher.unwrap();
const { owner, programs, expiry, codeUploading } = voucher.unwrap();

return {
owner: owner.toHex(),
programs: programs.unwrapOrDefault().toJSON() as string[],
expiry: expiry.toNumber(),
codeUploading: codeUploading.isTrue,
};
}

Expand Down
8 changes: 6 additions & 2 deletions api/src/types/interfaces/voucher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ export interface IVoucherDetails {
*/
owner: HexString;
/**
* The voucher validity.
* The block number at and after which voucher couldn't be used and can be revoked by owner.
*/
expiry: number;
/**
* The voucher programs.
* Set of programs this voucher could be used to interact with.
*/
programs: string[];
/**
* Flag if this voucher's covers uploading codes as prepaid call.
*/
codeUploading: boolean;
}
4 changes: 3 additions & 1 deletion api/test/Voucher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,13 @@ describe('Voucher', () => {
expect(details).toHaveProperty('programs');
expect(details).toHaveProperty('owner');
expect(details).toHaveProperty('expiry');
expect(Object.keys(details)).toHaveLength(3);
expect(details).toHaveProperty('codeUploading');
expect(Object.keys(details)).toHaveLength(4);
expect(details.programs).toHaveLength(1);
expect(details.programs[0]).toBe(programId);
expect(details.owner).toBe(decodeAddress(alice.address));
expect(details.expiry).toBe(validUpTo);
expect(details.codeUploading).toBeTruthy();
});

test('Send msg with voucher', async () => {
Expand Down

0 comments on commit 4d33de1

Please sign in to comment.