Skip to content

Commit

Permalink
add rawLogs to injective tx if they are not present
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Scatularo committed Nov 26, 2024
1 parent c05c619 commit 419fdd2
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/hooks/useHandleTransfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ import { useSeiWallet } from "../contexts/SeiWalletContext";
import { SeiWallet } from "@xlabs-libs/wallet-aggregator-sei";
import { SuiTransactionBlockResponse } from "@mysten/sui.js";
import { telemetry, TelemetryTxEvent } from "../utils/telemetry";
import { TxResponse } from "@injectivelabs/sdk-ts";

type AdditionalPayloadOverride = {
receivingContract: Uint8Array;
Expand Down Expand Up @@ -804,6 +805,31 @@ async function terra(
}
}

/**
* if raw tx logs are not present, add them to the tx object
* @param tx
* @returns tx with raw logs
*
* Note: applied the fix here, since wormhole sdk has been deprecated
*/
function addInjectiveRawLogsToTx(tx: TxResponse): TxResponse {
if (!!tx.rawLog || tx.rawLog.length === 0) {
const decoder = new TextDecoder();
const events = tx.events || [];
const rawLogs = events.map((event) => ({
type: event.type,
attributes: event.attributes.map(
(attr: { key: Uint8Array; value: Uint8Array }) => ({
key: attr.key instanceof Uint8Array ? decoder.decode(attr.key) : attr.key,
value: attr.value instanceof Uint8Array ? decoder.decode(attr.value) : attr.value,
})
),
}));
tx.rawLog = JSON.stringify([{ events: rawLogs }]);
}
return tx;
}

async function injective(
dispatch: any,
enqueueSnackbar: any,
Expand Down Expand Up @@ -848,7 +874,7 @@ async function injective(
enqueueSnackbar(null, {
content: <Alert severity="success">Transaction confirmed</Alert>,
});
const sequence = parseSequenceFromLogInjective(tx);
const sequence = parseSequenceFromLogInjective(addInjectiveRawLogsToTx(tx));
if (!sequence) {
throw new Error("Sequence not found");
}
Expand Down

0 comments on commit 419fdd2

Please sign in to comment.