Skip to content

Commit

Permalink
update Saved Tx to render correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jeesunikim committed Jan 17, 2025
1 parent 70458fc commit 6761266
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { sanitizeObject } from "@/helpers/sanitizeObject";
import { shareableUrl } from "@/helpers/shareableUrl";
import { getClaimableBalanceIdFromXdr } from "@/helpers/getClaimableBalanceIdFromXdr";
import { localStorageSavedTransactions } from "@/helpers/localStorageSavedTransactions";
import { isSorobanOperationType } from "@/helpers/sorobanUtils";

import { OP_SET_TRUST_LINE_FLAGS } from "@/constants/settings";
import { TRANSACTION_OPERATIONS } from "@/constants/transactionOperations";
Expand Down Expand Up @@ -924,13 +925,6 @@ export const Operations = () => {
TRANSACTION_OPERATIONS[e.target.value]?.defaultParams || {};
const defaultParamKeys = Object.keys(defaultParams);

const isSorobanOperationType = (operationType: string) => {
return [
"extend_footprint_ttl",
"restore_footprint",
"invoke_host_function",
].includes(operationType);
};
if (isSorobanOperationType(e.target.value)) {
updateSorobanBuildOperation({
operation_type: e.target.value,
Expand Down
18 changes: 16 additions & 2 deletions src/app/(sidebar)/transaction/saved/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { TRANSACTION_OPERATIONS } from "@/constants/transactionOperations";
import { useStore } from "@/store/useStore";
import { localStorageSavedTransactions } from "@/helpers/localStorageSavedTransactions";
import { arrayItem } from "@/helpers/arrayItem";
import { isSorobanOperationType } from "@/helpers/sorobanUtils";

import { SavedTransaction, SavedTransactionPage } from "@/types/types";

Expand Down Expand Up @@ -50,18 +51,31 @@ export default function SavedTransactions() {
const found = findLocalStorageTx(timestamp);

if (found) {
let isSorobanTx = false;

router.push(Routes.BUILD_TRANSACTION);

if (found.params) {
transaction.setBuildParams(found.params);
}

if (found.operations) {
transaction.updateBuildOperations(found.operations);
isSorobanTx = isSorobanOperationType(
found?.operations?.[0]?.operation_type,
);
if (isSorobanTx) {
transaction.updateSorobanBuildOperation(found.operations[0]);
} else {
transaction.updateBuildOperations(found.operations);
}
}

if (found.xdr) {
transaction.updateBuildXdr(found.xdr);
if (isSorobanTx) {
transaction.updateSorobanBuildXdr(found.xdr);
} else {
transaction.updateBuildXdr(found.xdr);
}
}
}
};
Expand Down
66 changes: 29 additions & 37 deletions src/helpers/sorobanUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@ import {
import { TransactionBuildParams } from "@/store/createStore";
import { SorobanOpType } from "@/types/types";

export const transactionHashFromXdr = (
xdr: string,
networkPassphrase: string,
) => {
try {
// Code to read XDR data
return TransactionBuilder?.fromXDR(xdr, networkPassphrase)
.hash()
.toString("hex");
} catch (e) {
// @TODO Do nothing for now
// add amplitude error tracking
return;
}
export const isSorobanOperationType = (operationType: string) => {
return [
"extend_footprint_ttl",
"restore_footprint",
"invoke_host_function",
].includes(operationType);
};

// https://developers.stellar.org/docs/learn/glossary#ledgerkey
Expand Down Expand Up @@ -92,29 +84,6 @@ export const getSorobanDataResult = ({
}
};

const buildSorobanData = ({
readOnlyXdrLedgerKey = [],
readWriteXdrLedgerKey = [],
resourceFee,
// instructionsm
// ReadableByteStreamController,
}: {
readOnlyXdrLedgerKey?: xdr.LedgerKey[];
readWriteXdrLedgerKey?: xdr.LedgerKey[];
resourceFee: string;
}) => {
// one of the two must be provided
if (!readOnlyXdrLedgerKey && !readWriteXdrLedgerKey) {
return;
}

return new SorobanDataBuilder()
.setReadOnly(readOnlyXdrLedgerKey)
.setReadWrite(readWriteXdrLedgerKey)
.setResourceFee(resourceFee)
.build();
};

export const buildSorobanTx = ({
sorobanData,
params,
Expand Down Expand Up @@ -179,3 +148,26 @@ export const buildSorobanTx = ({
)
.build();
};

const buildSorobanData = ({
readOnlyXdrLedgerKey = [],
readWriteXdrLedgerKey = [],
resourceFee,
// instructionsm
// ReadableByteStreamController,
}: {
readOnlyXdrLedgerKey?: xdr.LedgerKey[];
readWriteXdrLedgerKey?: xdr.LedgerKey[];
resourceFee: string;
}) => {
// one of the two must be provided
if (!readOnlyXdrLedgerKey && !readWriteXdrLedgerKey) {
return;
}

return new SorobanDataBuilder()
.setReadOnly(readOnlyXdrLedgerKey)
.setReadWrite(readWriteXdrLedgerKey)
.setResourceFee(resourceFee)
.build();
};

0 comments on commit 6761266

Please sign in to comment.