Skip to content

Commit e17de78

Browse files
Check if grant is finalized when making the continuation request
1 parent 211313e commit e17de78

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

grant/grant-continuation.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ const grant = await client.grant.continue(
3939
},
4040
);
4141

42+
if (!isFinalizedGrant(grant)) {
43+
throw new Error("Expected finalized grant. Received non-finalized grant.");
44+
}
45+
4246
console.log(
4347
"\x1b[34mNote: \x1b[0mIf you requested a grant with the `pnpm grant` script, the following `OUTGOING_PAYMENT_ACCESS_TOKEN` and `OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL` can be used for Incoming Payments and Quotes as well.\n",
4448
);
49+
4550
console.log("OUTGOING_PAYMENT_ACCESS_TOKEN =", grant.access_token.value);
4651
console.log("OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL =", grant.access_token.manage);

grant/grant-continuation.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const URL_WITH_INTERACT_REF = process.env.URL_WITH_INTERACT_REF;
1414
const PRIVATE_KEY_PATH = process.env.PRIVATE_KEY_PATH;
1515

1616
//@! start chunk 1 | title=Import dependencies
17-
import { createAuthenticatedClient } from "@interledger/open-payments";
17+
import { createAuthenticatedClient, isFinalizedGrant } from "@interledger/open-payments";
1818
//@! end chunk 1
1919

2020
//@! start chunk 2 | title=Initialize Open Payments client
@@ -45,10 +45,16 @@ const grant = await client.grant.continue(
4545
);
4646
//@! end chunk 3
4747

48+
//@! start chunk 4 | title=Check grant state
49+
if (!isFinalizedGrant(grant)) {
50+
throw new Error("Expected finalized grant. Received non-finalized grant.");
51+
}
52+
//@! end chunk4
53+
4854
console.log(
4955
"\x1b[34mNote: \x1b[0mIf you requested a grant with the `pnpm grant` script, the following `OUTGOING_PAYMENT_ACCESS_TOKEN` and `OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL` can be used for Incoming Payments and Quotes as well.\n",
5056
);
51-
//@! start chunk 4 | title=Output
57+
//@! start chunk 5 | title=Output
5258
console.log("OUTGOING_PAYMENT_ACCESS_TOKEN =", grant.access_token.value);
5359
console.log("OUTGOING_PAYMENT_ACCESS_TOKEN_MANAGE_URL =", grant.access_token.manage);
54-
//@! end chunk 4
60+
//@! end chunk 5

0 commit comments

Comments
 (0)