@ledgerhq/live-common
Version:
Common ground for the Ledger Live apps
51 lines • 1.76 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.applyMemoToTransaction = applyMemoToTransaction;
const memoApplicationRegistry = {
solana: (memo, _type, transaction) => {
const currentModel = transaction.model || {};
const currentUiState = currentModel.uiState || {};
return {
model: {
...currentModel,
uiState: {
...currentUiState,
memo,
},
},
};
},
casper: memo => ({ transferId: memo }),
xrp: memo => {
if (typeof memo === "number")
return { tag: memo };
if (typeof memo === "string")
return { tag: Number(memo) };
return { tag: undefined };
},
stellar: (memo, type) => ({ memoValue: memo, memoType: type }),
ton: (memo, _type, transaction) => {
const currentComment = transaction.comment || {};
return {
comment: {
...currentComment,
text: memo,
},
};
},
};
function applyMemoToTransaction(family, memoValue, memoTypeOrTransaction, currentTransaction) {
const isRecord = (value) => typeof value === "object" && value !== null;
const memoType = memoTypeOrTransaction === undefined || typeof memoTypeOrTransaction === "string"
? memoTypeOrTransaction
: undefined;
const transaction = isRecord(memoTypeOrTransaction)
? memoTypeOrTransaction
: currentTransaction ?? {};
const applyFn = memoApplicationRegistry[family];
if (!applyFn) {
return { memo: memoValue };
}
return applyFn(memoValue, memoType, transaction);
}
//# sourceMappingURL=memo.js.map