UNPKG

@ledgerhq/live-common

Version:
42 lines 2.38 kB
import { getSendDescriptor } from "../registry"; /** Builds a (currency) => T helper that reads from the send descriptor with a fallback when missing. */ function fromDescriptor(getter, fallback) { return currency => { const d = getSendDescriptor(currency); return d ? getter(d) ?? fallback : fallback; }; } export const sendFeatures = { canSendMax: fromDescriptor(d => d.amount?.canSendMax, true), hasMemo: fromDescriptor(d => d.inputs.memo != null, false), hasFeePresets: fromDescriptor(d => d.fees.hasPresets, false), hasCustomFees: fromDescriptor(d => d.fees.hasCustom, false), getCustomFeeConfig: fromDescriptor(d => d.fees.custom, null), hasCustomAssets: fromDescriptor(d => d.fees.hasCustomAssets, false), getCustomAssetsConfig: fromDescriptor(d => d.fees.customAssets, null), hasCoinControl: fromDescriptor(d => d.fees.hasCoinControl, false), getFeePresetOptions: (currency, transaction) => { const d = getSendDescriptor(currency); return d?.fees.presets?.getOptions?.(transaction) ?? []; }, shouldEstimateFeePresetsWithBridge: (currency, transaction) => { const d = getSendDescriptor(currency); return d?.fees.presets?.shouldEstimateWithBridge?.(transaction) ?? false; }, getAmountPlugins: fromDescriptor(d => d.amount?.getPlugins?.(), []), getMemoType: fromDescriptor(d => d.inputs.memo?.type, undefined), getMemoMaxLength: fromDescriptor(d => d.inputs.memo?.maxLength, undefined), getMemoMaxValue: fromDescriptor(d => d.inputs.memo?.maxValue, undefined), getMemoOptions: fromDescriptor(d => d.inputs.memo?.options, undefined), getMemoDefaultOption: fromDescriptor(d => d.inputs.memo?.defaultOption, undefined), supportsDomain: fromDescriptor(d => d.inputs.recipientSupportsDomain, false), getSelfTransferPolicy: fromDescriptor(d => d.selfTransfer, "impossible"), getUserRefusedTransactionErrorName: fromDescriptor(d => d.errors?.userRefusedTransaction, "TransactionRefusedOnDevice"), isUserRefusedTransactionError: (currency, error) => { if (!currency) return false; const errorName = sendFeatures.getUserRefusedTransactionErrorName(currency); return (error !== null && typeof error === "object" && "name" in error && error.name === errorName); }, }; //# sourceMappingURL=features.js.map