Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/great-mails-warn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@safe-global/safe-apps-provider': patch
---

Update EIP-5792 implementation according to spec. and fix pending status
27 changes: 18 additions & 9 deletions packages/safe-apps-provider/src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,23 @@
[TransactionStatus.SUCCESS]: 'CONFIRMED',
};

const tx = await this.sdk.txs.getBySafeTxHash(params[0]).catch(() => null);
if (!tx?.txHash) {
throw new Error('Transaction not found');
const tx = await this.sdk.txs.getBySafeTxHash(params[0]);

const status = CallStatus[tx.txStatus];

// Transaction is queued
if (!tx.txHash) {
return {
status,
};
}

const receipt = await this.sdk.eth.getTransactionReceipt([tx.txHash]).catch(() => null);
// If transaction is executing, receipt is null
const receipt = await this.sdk.eth.getTransactionReceipt([tx.txHash]);
if (!receipt) {
throw new Error('Transaction receipt not found');
return {
status,
};
}

const calls =
Expand All @@ -255,17 +264,17 @@
const gasUsed = Number(receipt.gasUsed);

const receipts = Array(calls).fill({
success: numberToHex(tx.txStatus === TransactionStatus.SUCCESS ? 1 : 0),
logs: receipt.logs,
status: numberToHex(tx.txStatus === TransactionStatus.SUCCESS ? 1 : 0),
chainId: numberToHex(this.chainId),
blockHash: receipt.blockHash,
blockNumber: numberToHex(blockNumber),
blockTimestamp: numberToHex(tx.executedAt ?? 0),
gasUsed: numberToHex(gasUsed),
transactionHash: tx.txHash,
logs: receipt.logs,
});

return {
status: CallStatus[tx.txStatus],
status,
receipts,
};
}
Expand All @@ -292,7 +301,7 @@

// this method is needed for ethers v4
// https://github.com/ethers-io/ethers.js/blob/427e16826eb15d52d25c4f01027f8db22b74b76c/src.ts/providers/web3-provider.ts#L41-L55
send(request: any, callback: (error: any, response?: any) => void): void {

Check warning on line 304 in packages/safe-apps-provider/src/provider.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type

Check warning on line 304 in packages/safe-apps-provider/src/provider.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type

Check warning on line 304 in packages/safe-apps-provider/src/provider.ts

View workflow job for this annotation

GitHub Actions / eslint

Unexpected any. Specify a different type
if (!request) callback('Undefined request');
this.request(request)
.then((result) => callback(null, { jsonrpc: '2.0', id: request.id, result }))
Expand Down
Loading