Skip to content

Commit

Permalink
Prepare for TX on XRPL Protocol with NetworkID
Browse files Browse the repository at this point in the history
  • Loading branch information
WietseWind committed Apr 19, 2024
1 parent 7d1dc6f commit 7716131
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/families/ripple/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { getEnv } from "@ledgerhq/live-env";
import { retry } from "../../../promise";
import { NEW_ACCOUNT_ERROR_MESSAGE } from "../bridge/js";

// TODO: Pick different RPC endpoint if on another XRPL Protocol based chain

const defaultEndpoint = () => getEnv("API_RIPPLE_RPC");

export const connectionTimeout = 30 * 1000; // default connectionTimeout is 2s and make the specs bot failed
Expand Down
7 changes: 7 additions & 0 deletions libs/ledger-live-common/src/families/ripple/bridge/js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,19 @@ const signOperation: SignOperationFnSignature<Transaction> = ({ account, transac
try {
const tag = transaction.tag ? transaction.tag : undefined;
const nextSequenceNumber = await getNextValidSequence(account);
const NetworkID = // XRPL mainnet = 0, other networks may need NetworkID
transaction.networkInfo?.networkId || 0 > 1024
? transaction.networkInfo?.networkId
: undefined;

const payment = {
TransactionType: "Payment",
Account: account.freshAddress,
Amount: transaction.amount.toString(),
Destination: transaction.recipient,
DestinationTag: tag,
Fee: fee.toString(),
NetworkID,
Flags: 2147483648,
Sequence: nextSequenceNumber,
LastLedgerSequence: (await getLedgerIndex()) + LEDGER_OFFSET,
Expand Down Expand Up @@ -214,6 +220,7 @@ const prepareTransaction = async (a: Account, t: Transaction): Promise<Transacti
networkInfo = {
family: "ripple",
serverFee,
networkId: info.info?.network_id || 0,
baseReserve: new BigNumber(0), // NOT USED. will refactor later.
};
} catch (e) {
Expand Down
5 changes: 5 additions & 0 deletions libs/ledger-live-common/src/families/ripple/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import {
import type { Account } from "@ledgerhq/types-live";
import { getAccountUnit } from "../../account";
import { formatCurrencyUnit } from "../../currencies";

// TODO: Pick different RPC endpoint if on another XRPL Protocol based chain

export const formatTransaction = (
{ amount, recipient, fee, tag, useAllAmount }: Transaction,
account: Account,
Expand Down Expand Up @@ -43,6 +46,7 @@ export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
// FIXME remove this field. this is not good.. we're dereferencing here. we should instead store an index (to lookup in currency.units on UI)
networkInfo: networkInfo && {
family: networkInfo.family,
networkId: networkInfo?.networkId || 0,
serverFee: new BigNumber(networkInfo.serverFee),
baseReserve: new BigNumber(networkInfo.baseReserve),
},
Expand All @@ -61,6 +65,7 @@ export const toTransactionRaw = (t: Transaction): TransactionRaw => {
networkInfo: networkInfo && {
family: networkInfo.family,
serverFee: networkInfo.serverFee.toString(),
networkId: networkInfo?.networkId || 0,
baseReserve: networkInfo.baseReserve.toString(),
},
};
Expand Down
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/families/ripple/types.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export interface TxXRPL {
tx: {
TransactionType: string;
Fee: string;
NetworkID?: number;
Account: string;
Destination: string;
DestinationTag?: number;
Amount: string;
Sequence: number;
date: number;
inLedger: number;
ctid?: string;
hash: string;
};
}
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/families/ripple/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import type {
export type NetworkInfo = {
family: "ripple";
serverFee: BigNumber;
networkId: number;
baseReserve: BigNumber;
};
export type NetworkInfoRaw = {
family: "ripple";
serverFee: string;
networkId: number;
baseReserve: string;
};
export type Transaction = TransactionCommon & {
Expand Down

0 comments on commit 7716131

Please sign in to comment.