Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTrunk committed Nov 8, 2024
1 parent c563723 commit 900d82f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/services/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ async function sendNotificationKey(wkIdentity, data) {
try {
if (data.payload && data.action === 'tx') {
const decodedTransaction: decodedTx =
transactionDecoder.decodeTransactionForApproval(
await transactionDecoder.decodeTransactionForApproval(
data.payload,
data.chain,
);
Expand Down
25 changes: 16 additions & 9 deletions src/services/transactionDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function getLibId(chain) {
return blockchains[chain].libid;
}

function decodeEVMTransactionForApproval(rawTx, chain = 'eth') {
async function decodeEVMTransactionForApproval(rawTx, chain = 'eth') {
try {
let { decimals } = blockchains[chain];
const multisigUserOpJSON = JSON.parse(rawTx);
Expand Down Expand Up @@ -74,14 +74,20 @@ function decodeEVMTransactionForApproval(rawTx, chain = 'eth') {
txInfo.token = decodedData.args[0] as string;

// find the token in our token list
let token: any = {};

token = blockchains[chain].tokens.find(
let token = blockchains[chain].tokens.find(
(t) => t.contract.toLowerCase() === txInfo.token.toLowerCase(),
);

if (Object.keys(token).length <= 0) {
token = getFromAlchemy(txInfo.token.toLowerCase(), chain.toLowerCase());

if (!token) {
token = await getFromAlchemy(
txInfo.token.toLowerCase(), // contract address
chain.toLowerCase(), // chain
).catch((error) => {
log.error(
`Error getting token info from alchemy for ${txInfo.token} on ${chain}`,
);
log.error(error);
});
}

if (token) {
Expand Down Expand Up @@ -122,10 +128,11 @@ function decodeEVMTransactionForApproval(rawTx, chain = 'eth') {
}
}

function decodeTransactionForApproval(rawTx, chain = 'btc') {
async function decodeTransactionForApproval(rawTx, chain = 'btc') {
try {
if (blockchains[chain].chainType === 'evm') {
return decodeEVMTransactionForApproval(rawTx, chain);
const decoded = await decodeEVMTransactionForApproval(rawTx, chain);
return decoded;
}
log.info('Decoding transaction for approval');
log.info(rawTx);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/transactionDecoder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ describe('Transaction Decoder', function () {
});
});

it('should return error result if raw tx is invalid for sepolia', async function () {
it('should return error result if raw tx is invalid for sepolia', async function () {
const response = await transactionDecoder.decodeTransactionForApproval(
JSON.stringify(invalidRawTxSepolia),
'sepolia',
Expand Down

0 comments on commit 900d82f

Please sign in to comment.