Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rawLogs to injective tx if they are not present #1197

Merged
Merged
Changes from all 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
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
Loading