Skip to content

Commit

Permalink
Merge pull request #6 from MyTonSwap/develop
Browse files Browse the repository at this point in the history
fix: tonapi transaction status logic update
  • Loading branch information
Ho3einWave authored Dec 26, 2024
2 parents 9110a49 + c714a39 commit a333fcc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
Binary file modified bun.lockb
Binary file not shown.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
"tsup": "^8.3.0"
},
"peerDependencies": {
"@ton/ton": "^15.0.0",
"typescript": "^5.0.0"
},
"dependencies": {
"@lifeomic/attempt": "^3.1.0",
"axios": "^1.7.7",
"lodash": "^4.17.21"
"lodash": "^4.17.21",
"@ton/ton": "^15.0.0"
}
}
11 changes: 5 additions & 6 deletions src/services/tonapi/tonapi.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class TonApi extends Services {
while (retries <= maxRetry) {
try {
let result = await this.client.tonapi.getTransactionEvent(hash);
while (!this.allTransactionComplete(result)) {
while (this.allTransactionComplete(result) === 'inprogress') {
await new Promise((resolve) => setTimeout(resolve, period_ms));
result = await this.client.tonapi.getTransactionEvent(hash);
retries++;
Expand Down Expand Up @@ -188,13 +188,12 @@ export class TonApi extends Services {
* Checks if all transactions in the given event are complete.
*
* @param {TransactionEvent} event - The transaction event to check.
* @returns {boolean} - Returns `true` if all transactions are complete and successful, otherwise `false`.
* @returns {string} - Returns `ok` if all transactions are complete and successful, otherwise `failed` or `inprogress`.
* @throws {Error} - Throws an error if any transaction action has a status other than 'ok'.
*/
public allTransactionComplete(event: TransactionEvent) {
if (event.in_progress) return false;
if (event.actions.some((item) => item.status !== 'ok'))
throw new Error('Transaction failed');
return true;
if (event.in_progress) return 'inprogress';
if (event.actions.some((item) => item.status !== 'ok')) return 'failed';
return 'ok';
}
}

0 comments on commit a333fcc

Please sign in to comment.