Skip to content

Commit

Permalink
feat(fund with ar): throw no wallet found as error PE-5849
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Mar 29, 2024
1 parent 05dc210 commit d1d2e7a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
8 changes: 5 additions & 3 deletions examples/cjs/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})();
8 changes: 5 additions & 3 deletions examples/esm/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})();
8 changes: 5 additions & 3 deletions examples/typescript/cjs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})();
8 changes: 5 additions & 3 deletions examples/typescript/esm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
})();
6 changes: 5 additions & 1 deletion src/common/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}

Check warning on line 287 in src/common/payment.ts

View check run for this annotation

Codecov / codecov/patch

src/common/payment.ts#L286-L287

Added lines #L286 - L287 were not covered by tests
return walletAddress;
}

public async topUpWithTokens({
Expand Down

0 comments on commit d1d2e7a

Please sign in to comment.