From 452a06a2aca2da42d161e867652b8084a404b81f Mon Sep 17 00:00:00 2001 From: Sebastian Scatularo Date: Wed, 27 Nov 2024 16:50:10 -0300 Subject: [PATCH] extend fix to attest flow --- src/hooks/useHandleAttest.tsx | 7 +++++-- src/hooks/useHandleTransfer.tsx | 37 ++++----------------------------- src/utils/injective.ts | 32 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/hooks/useHandleAttest.tsx b/src/hooks/useHandleAttest.tsx index 563718040..61ea755ff 100644 --- a/src/hooks/useHandleAttest.tsx +++ b/src/hooks/useHandleAttest.tsx @@ -96,7 +96,10 @@ import { signSendAndConfirm } from "../utils/solana"; import { postWithFees, waitForTerraExecution } from "../utils/terra"; import { postWithFeesXpla, waitForXplaExecution } from "../utils/xpla"; import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; -import { broadcastInjectiveTx } from "../utils/injective"; +import { + addInjectiveRawLogsToTx, + broadcastInjectiveTx, +} from "../utils/injective"; import { AlgorandWallet } from "@xlabs-libs/wallet-aggregator-algorand"; import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana"; import { AptosWallet } from "@xlabs-libs/wallet-aggregator-aptos"; @@ -544,7 +547,7 @@ async function injective( enqueueSnackbar(null, { content: Transaction confirmed, }); - const sequence = parseSequenceFromLogInjective(tx); + const sequence = parseSequenceFromLogInjective(addInjectiveRawLogsToTx(tx)); if (!sequence) { throw new Error("Sequence not found"); } diff --git a/src/hooks/useHandleTransfer.tsx b/src/hooks/useHandleTransfer.tsx index 55a2a83fc..53c13c989 100644 --- a/src/hooks/useHandleTransfer.tsx +++ b/src/hooks/useHandleTransfer.tsx @@ -121,7 +121,10 @@ import { signSendAndConfirm } from "../utils/solana"; import { postWithFees, waitForTerraExecution } from "../utils/terra"; import useTransferTargetAddressHex from "./useTransferTargetAddress"; import { postWithFeesXpla, waitForXplaExecution } from "../utils/xpla"; -import { broadcastInjectiveTx } from "../utils/injective"; +import { + addInjectiveRawLogsToTx, + broadcastInjectiveTx, +} from "../utils/injective"; import { useInjectiveContext } from "../contexts/InjectiveWalletContext"; import { AlgorandWallet } from "@xlabs-libs/wallet-aggregator-algorand"; import { SolanaWallet } from "@xlabs-libs/wallet-aggregator-solana"; @@ -149,7 +152,6 @@ 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; @@ -805,37 +807,6 @@ 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, diff --git a/src/utils/injective.ts b/src/utils/injective.ts index 64e04d8fc..5691f2fa1 100644 --- a/src/utils/injective.ts +++ b/src/utils/injective.ts @@ -4,6 +4,7 @@ import { ChainGrpcWasmApi, Msgs, TxGrpcClient, + TxResponse, } from "@injectivelabs/sdk-ts"; import { InjectiveWallet } from "@xlabs-libs/wallet-aggregator-injective"; import { getInjectiveNetworkInfo } from "./consts"; @@ -60,3 +61,34 @@ export const broadcastInjectiveTx = async ( } return tx; }; + +/** + * 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 + */ +export 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; +}