diff --git a/examples/cjs/index.cjs b/examples/cjs/index.cjs index 371b2e32..09701190 100644 --- a/examples/cjs/index.cjs +++ b/examples/cjs/index.cjs @@ -86,8 +86,10 @@ const { * Tops up a wallet with Credits using tokens. * Default token is AR, using Winston as the unit. */ - const topUpResult = await turboAuthClient.topUpWithTokens({ - tokenAmount: 1, /// 0.000_000_000_000_001 AR - }); + const topUpResult = await turboAuthClient + .topUpWithTokens({ + tokenAmount: 1, /// 0.000_000_000_000_001 AR + }) + .catch((err) => err); // Will throw an error with a wallet that has no tokens console.log(JSON.stringify(topUpResult, null, 2)); })(); diff --git a/examples/esm/index.mjs b/examples/esm/index.mjs index f4d74c24..52579b85 100644 --- a/examples/esm/index.mjs +++ b/examples/esm/index.mjs @@ -83,8 +83,10 @@ import fs from 'fs'; * Tops up a wallet with Credits using tokens. * Default token is AR, using Winston as the unit. */ - const topUpResult = await turboAuthClient.topUpWithTokens({ - tokenAmount: 1, /// 0.000_000_000_000_001 AR - }); + const topUpResult = await turboAuthClient + .topUpWithTokens({ + tokenAmount: 1, /// 0.000_000_000_000_001 AR + }) + .catch((err) => err); // Will throw an error with a wallet that has no tokens; console.log(JSON.stringify(topUpResult, null, 2)); })(); diff --git a/examples/typescript/cjs/index.ts b/examples/typescript/cjs/index.ts index b36e54d5..f1cb3991 100644 --- a/examples/typescript/cjs/index.ts +++ b/examples/typescript/cjs/index.ts @@ -52,8 +52,10 @@ import path from 'path'; * Tops up a wallet with Credits using tokens. * Default token is AR, using Winston as the unit. */ - const topUpResult = await turboAuthClient.topUpWithTokens({ - tokenAmount: 1, /// 0.000_000_000_000_001 AR - }); + const topUpResult = await turboAuthClient + .topUpWithTokens({ + tokenAmount: 1, /// 0.000_000_000_000_001 AR + }) + .catch((err) => err); // Will throw an error with a wallet that has no tokens; console.log(JSON.stringify(topUpResult, null, 2)); })(); diff --git a/examples/typescript/esm/index.ts b/examples/typescript/esm/index.ts index acbb4e2e..ef44ec73 100644 --- a/examples/typescript/esm/index.ts +++ b/examples/typescript/esm/index.ts @@ -52,8 +52,10 @@ import fs from 'fs'; * Tops up a wallet with Credits using tokens. * Default token is AR, using Winston as the unit. */ - const topUpResult = await turboAuthClient.topUpWithTokens({ - tokenAmount: 1, /// 0.000_000_000_000_001 AR - }); + const topUpResult = await turboAuthClient + .topUpWithTokens({ + tokenAmount: 1, /// 0.000_000_000_000_001 AR + }) + .catch((err) => err); // Will throw an error with a wallet that has no tokens; console.log(JSON.stringify(topUpResult, null, 2)); })(); diff --git a/src/common/payment.ts b/src/common/payment.ts index 874b525e..79c50d23 100644 --- a/src/common/payment.ts +++ b/src/common/payment.ts @@ -281,7 +281,11 @@ export class TurboAuthenticatedPaymentService endpoint: '/info', }); - return addresses[this.token]; + const walletAddress = addresses[this.token]; + if (!walletAddress) { + throw new Error(`No wallet address found for token type: ${this.token}`); + } + return walletAddress; } public async topUpWithTokens({