@ledgerhq/coin-xrp 7.1.0 → 7.1.1-nightly.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +1 -0
- package/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +3 -1
- package/CHANGELOG.md +24 -0
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +19 -6
- package/lib/api/index.js.map +1 -1
- package/lib/api/index.test.js +1 -1
- package/lib/api/index.test.js.map +1 -1
- package/lib/logic/craftTransaction.d.ts +1 -1
- package/lib/logic/craftTransaction.d.ts.map +1 -1
- package/lib/logic/craftTransaction.js +1 -1
- package/lib/logic/craftTransaction.js.map +1 -1
- package/lib/logic/craftTransaction.test.js +2 -2
- package/lib/logic/craftTransaction.test.js.map +1 -1
- package/lib/logic/estimateFees.d.ts +1 -1
- package/lib/logic/estimateFees.d.ts.map +1 -1
- package/lib/logic/estimateFees.js +1 -1
- package/lib/logic/estimateFees.js.map +1 -1
- package/lib/logic/estimateFees.test.js +2 -2
- package/lib/logic/estimateFees.test.js.map +1 -1
- package/lib/logic/getTransactionStatus.d.ts +3 -2
- package/lib/logic/getTransactionStatus.d.ts.map +1 -1
- package/lib/logic/getTransactionStatus.js +35 -25
- package/lib/logic/getTransactionStatus.js.map +1 -1
- package/lib/logic/getTransactionStatus.test.js +108 -27
- package/lib/logic/getTransactionStatus.test.js.map +1 -1
- package/lib/logic/listOperations.js +5 -5
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/listOperations.test.js +5 -5
- package/lib/logic/listOperations.test.js.map +1 -1
- package/lib/test/bridgeDatasetTest.js +4 -4
- package/lib/test/bridgeDatasetTest.js.map +1 -1
- package/lib/test/cli.js +1 -1
- package/lib/test/cli.js.map +1 -1
- package/lib/transaction.d.ts +2 -2
- package/lib/transaction.d.ts.map +1 -1
- package/lib/transaction.js +5 -5
- package/lib/transaction.js.map +1 -1
- package/lib/types/bridge.d.ts +2 -2
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +19 -6
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/api/index.test.js +1 -1
- package/lib-es/api/index.test.js.map +1 -1
- package/lib-es/logic/craftTransaction.d.ts +1 -1
- package/lib-es/logic/craftTransaction.d.ts.map +1 -1
- package/lib-es/logic/craftTransaction.js +1 -1
- package/lib-es/logic/craftTransaction.js.map +1 -1
- package/lib-es/logic/craftTransaction.test.js +2 -2
- package/lib-es/logic/craftTransaction.test.js.map +1 -1
- package/lib-es/logic/estimateFees.d.ts +1 -1
- package/lib-es/logic/estimateFees.d.ts.map +1 -1
- package/lib-es/logic/estimateFees.js +1 -1
- package/lib-es/logic/estimateFees.js.map +1 -1
- package/lib-es/logic/estimateFees.test.js +2 -2
- package/lib-es/logic/estimateFees.test.js.map +1 -1
- package/lib-es/logic/getTransactionStatus.d.ts +3 -2
- package/lib-es/logic/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/logic/getTransactionStatus.js +35 -25
- package/lib-es/logic/getTransactionStatus.js.map +1 -1
- package/lib-es/logic/getTransactionStatus.test.js +108 -27
- package/lib-es/logic/getTransactionStatus.test.js.map +1 -1
- package/lib-es/logic/listOperations.js +5 -5
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/listOperations.test.js +5 -5
- package/lib-es/logic/listOperations.test.js.map +1 -1
- package/lib-es/test/bridgeDatasetTest.js +4 -4
- package/lib-es/test/bridgeDatasetTest.js.map +1 -1
- package/lib-es/test/cli.js +1 -1
- package/lib-es/test/cli.js.map +1 -1
- package/lib-es/transaction.d.ts +2 -2
- package/lib-es/transaction.d.ts.map +1 -1
- package/lib-es/transaction.js +5 -5
- package/lib-es/transaction.js.map +1 -1
- package/lib-es/types/bridge.d.ts +2 -2
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/api/index.test.ts +1 -1
- package/src/api/index.ts +20 -9
- package/src/logic/craftTransaction.test.ts +2 -2
- package/src/logic/craftTransaction.ts +2 -2
- package/src/logic/estimateFees.test.ts +2 -2
- package/src/logic/estimateFees.ts +2 -2
- package/src/logic/getTransactionStatus.test.ts +94 -28
- package/src/logic/getTransactionStatus.ts +38 -27
- package/src/logic/listOperations.test.ts +5 -5
- package/src/logic/listOperations.ts +5 -5
- package/src/test/bridgeDatasetTest.ts +4 -4
- package/src/test/cli.ts +1 -1
- package/src/transaction.ts +5 -5
- package/src/types/bridge.ts +2 -2
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { getTransactionStatus } from "./getTransactionStatus";
|
|
2
2
|
import * as utils from "./utils";
|
|
3
3
|
|
|
4
|
+
const mockGetBalance = jest.fn();
|
|
5
|
+
|
|
4
6
|
const mockGetServerInfos = jest.fn();
|
|
5
7
|
|
|
8
|
+
jest.mock("./getBalance", () => ({
|
|
9
|
+
getBalance: () => mockGetBalance(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
6
12
|
jest.mock("../network", () => ({
|
|
7
13
|
getServerInfos: () => mockGetServerInfos(),
|
|
8
14
|
}));
|
|
@@ -20,21 +26,9 @@ const SENDER = "rPSCfmnX3t9jQJG5RNcZtSaP5UhExZDue4";
|
|
|
20
26
|
const RECIPIENT = "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe";
|
|
21
27
|
const RECIPIENT_NEW = "rDKsbvy9uaNpPtvVFraJyNGfjvTw8xivgK";
|
|
22
28
|
|
|
23
|
-
const account = {
|
|
24
|
-
address: SENDER,
|
|
25
|
-
balance: 50_000_000n,
|
|
26
|
-
currencyUnit: {
|
|
27
|
-
code: "XRP",
|
|
28
|
-
magnitude: 6,
|
|
29
|
-
name: "XRP",
|
|
30
|
-
symbol: "XRP",
|
|
31
|
-
},
|
|
32
|
-
currencyName: "XRP",
|
|
33
|
-
};
|
|
34
|
-
|
|
35
29
|
describe("getTransactionStatus", () => {
|
|
36
30
|
afterEach(() => {
|
|
37
|
-
|
|
31
|
+
jest.clearAllMocks();
|
|
38
32
|
});
|
|
39
33
|
|
|
40
34
|
it("returns no errors on valid transaction", async () => {
|
|
@@ -45,13 +39,22 @@ describe("getTransactionStatus", () => {
|
|
|
45
39
|
},
|
|
46
40
|
},
|
|
47
41
|
});
|
|
42
|
+
mockGetBalance.mockResolvedValue([
|
|
43
|
+
{
|
|
44
|
+
value: 50_000_000n,
|
|
45
|
+
asset: { type: "native" },
|
|
46
|
+
locked: 0n,
|
|
47
|
+
},
|
|
48
|
+
]);
|
|
48
49
|
|
|
49
50
|
const result = await getTransactionStatus(
|
|
50
|
-
account as any,
|
|
51
|
+
// account as any,
|
|
51
52
|
{
|
|
53
|
+
sender: SENDER,
|
|
52
54
|
amount: 20_000_000n,
|
|
53
|
-
|
|
55
|
+
fees: 10_000n,
|
|
54
56
|
recipient: RECIPIENT,
|
|
57
|
+
asset: { unit: { code: "XRP", magnitude: 6 } },
|
|
55
58
|
} as any,
|
|
56
59
|
);
|
|
57
60
|
|
|
@@ -68,13 +71,22 @@ describe("getTransactionStatus", () => {
|
|
|
68
71
|
},
|
|
69
72
|
},
|
|
70
73
|
});
|
|
74
|
+
mockGetBalance.mockResolvedValue([
|
|
75
|
+
{
|
|
76
|
+
value: 50_000_000n,
|
|
77
|
+
asset: { type: "native" },
|
|
78
|
+
locked: 0n,
|
|
79
|
+
},
|
|
80
|
+
]);
|
|
71
81
|
|
|
72
82
|
const result = await getTransactionStatus(
|
|
73
|
-
account as any,
|
|
83
|
+
// account as any,
|
|
74
84
|
{
|
|
85
|
+
sender: SENDER,
|
|
75
86
|
amount: 1_000_000n,
|
|
76
|
-
|
|
87
|
+
fees: 200_000n, // 20%
|
|
77
88
|
recipient: RECIPIENT,
|
|
89
|
+
asset: { unit: { code: "XRP", magnitude: 6 } },
|
|
78
90
|
} as any,
|
|
79
91
|
);
|
|
80
92
|
|
|
@@ -90,12 +102,21 @@ describe("getTransactionStatus", () => {
|
|
|
90
102
|
},
|
|
91
103
|
},
|
|
92
104
|
});
|
|
105
|
+
mockGetBalance.mockResolvedValue([
|
|
106
|
+
{
|
|
107
|
+
value: 30_000_000n,
|
|
108
|
+
asset: { type: "native" },
|
|
109
|
+
locked: 0n,
|
|
110
|
+
},
|
|
111
|
+
]);
|
|
93
112
|
|
|
94
113
|
const result = await getTransactionStatus(
|
|
95
|
-
account as any,
|
|
114
|
+
// account as any,
|
|
96
115
|
{
|
|
116
|
+
sender: SENDER,
|
|
97
117
|
amount: 10_000_000n,
|
|
98
118
|
recipient: RECIPIENT,
|
|
119
|
+
asset: { unit: { code: "XRP", magnitude: 6 } },
|
|
99
120
|
} as any,
|
|
100
121
|
);
|
|
101
122
|
|
|
@@ -110,13 +131,22 @@ describe("getTransactionStatus", () => {
|
|
|
110
131
|
},
|
|
111
132
|
},
|
|
112
133
|
});
|
|
134
|
+
mockGetBalance.mockResolvedValue([
|
|
135
|
+
{
|
|
136
|
+
value: 50_000_000n,
|
|
137
|
+
asset: { type: "native" },
|
|
138
|
+
locked: 0n,
|
|
139
|
+
},
|
|
140
|
+
]);
|
|
113
141
|
|
|
114
142
|
const result = await getTransactionStatus(
|
|
115
|
-
account as any,
|
|
143
|
+
// account as any,
|
|
116
144
|
{
|
|
145
|
+
sender: SENDER,
|
|
117
146
|
amount: 10_000_000n,
|
|
118
|
-
|
|
147
|
+
fees: 10_000n,
|
|
119
148
|
recipient: SENDER,
|
|
149
|
+
asset: { unit: { code: "XRP", magnitude: 6 } },
|
|
120
150
|
} as any,
|
|
121
151
|
);
|
|
122
152
|
|
|
@@ -131,13 +161,22 @@ describe("getTransactionStatus", () => {
|
|
|
131
161
|
},
|
|
132
162
|
},
|
|
133
163
|
});
|
|
164
|
+
mockGetBalance.mockResolvedValue([
|
|
165
|
+
{
|
|
166
|
+
value: 50_000_000n,
|
|
167
|
+
asset: { type: "native" },
|
|
168
|
+
locked: 0n,
|
|
169
|
+
},
|
|
170
|
+
]);
|
|
134
171
|
|
|
135
172
|
const result = await getTransactionStatus(
|
|
136
|
-
account as any,
|
|
173
|
+
// account as any,
|
|
137
174
|
{
|
|
175
|
+
sender: SENDER,
|
|
138
176
|
amount: 5_000_000n,
|
|
139
|
-
|
|
177
|
+
fees: 10_000n,
|
|
140
178
|
recipient: RECIPIENT_NEW,
|
|
179
|
+
asset: { unit: { code: "XRP", magnitude: 6 } },
|
|
141
180
|
} as any,
|
|
142
181
|
);
|
|
143
182
|
|
|
@@ -152,13 +191,22 @@ describe("getTransactionStatus", () => {
|
|
|
152
191
|
},
|
|
153
192
|
},
|
|
154
193
|
});
|
|
194
|
+
mockGetBalance.mockResolvedValue([
|
|
195
|
+
{
|
|
196
|
+
value: 50_000_000n,
|
|
197
|
+
asset: { type: "native" },
|
|
198
|
+
locked: 0n,
|
|
199
|
+
},
|
|
200
|
+
]);
|
|
155
201
|
|
|
156
202
|
const result = await getTransactionStatus(
|
|
157
|
-
account as any,
|
|
203
|
+
// account as any,
|
|
158
204
|
{
|
|
205
|
+
sender: SENDER,
|
|
159
206
|
amount: 0n,
|
|
160
|
-
|
|
207
|
+
fees: 10_000n,
|
|
161
208
|
recipient: RECIPIENT,
|
|
209
|
+
asset: { unit: { code: "XRP", magnitude: 6 } },
|
|
162
210
|
} as any,
|
|
163
211
|
);
|
|
164
212
|
|
|
@@ -173,12 +221,21 @@ describe("getTransactionStatus", () => {
|
|
|
173
221
|
},
|
|
174
222
|
},
|
|
175
223
|
});
|
|
224
|
+
mockGetBalance.mockResolvedValue([
|
|
225
|
+
{
|
|
226
|
+
value: 50_000_000n,
|
|
227
|
+
asset: { type: "native" },
|
|
228
|
+
locked: 0n,
|
|
229
|
+
},
|
|
230
|
+
]);
|
|
176
231
|
|
|
177
232
|
const result = await getTransactionStatus(
|
|
178
|
-
account as any,
|
|
233
|
+
// account as any,
|
|
179
234
|
{
|
|
235
|
+
sender: SENDER,
|
|
236
|
+
asset: { unit: { code: "XRP", magnitude: 6 } },
|
|
180
237
|
amount: 1_000_000n,
|
|
181
|
-
|
|
238
|
+
fees: 10_000n,
|
|
182
239
|
recipient: "not-an-address",
|
|
183
240
|
} as any,
|
|
184
241
|
);
|
|
@@ -194,12 +251,21 @@ describe("getTransactionStatus", () => {
|
|
|
194
251
|
},
|
|
195
252
|
},
|
|
196
253
|
});
|
|
254
|
+
mockGetBalance.mockResolvedValue([
|
|
255
|
+
{
|
|
256
|
+
value: 50_000_000n,
|
|
257
|
+
asset: { type: "native" },
|
|
258
|
+
locked: 0n,
|
|
259
|
+
},
|
|
260
|
+
]);
|
|
197
261
|
|
|
198
262
|
const result = await getTransactionStatus(
|
|
199
|
-
account as any,
|
|
263
|
+
// account as any,
|
|
200
264
|
{
|
|
265
|
+
sender: SENDER,
|
|
266
|
+
asset: { unit: { code: "XRP", magnitude: 6 } },
|
|
201
267
|
amount: 1_000_000n,
|
|
202
|
-
|
|
268
|
+
fees: 10_000n,
|
|
203
269
|
recipient: "",
|
|
204
270
|
} as any,
|
|
205
271
|
);
|
|
@@ -14,11 +14,12 @@ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
|
14
14
|
import { getServerInfos } from "../network";
|
|
15
15
|
import { cachedRecipientIsNew } from "./utils";
|
|
16
16
|
import { parseAPIValue } from "./common";
|
|
17
|
-
import {
|
|
17
|
+
import { TransactionValidation, TransactionIntent } from "@ledgerhq/coin-framework/api/types";
|
|
18
|
+
import { XrpMapMemo } from "../types";
|
|
19
|
+
import { getBalance } from "./getBalance";
|
|
18
20
|
|
|
19
21
|
export const getTransactionStatus = async (
|
|
20
|
-
|
|
21
|
-
transaction: Transaction,
|
|
22
|
+
transactionIntent: TransactionIntent<XrpMapMemo>,
|
|
22
23
|
): Promise<TransactionValidation> => {
|
|
23
24
|
const errors: Record<string, Error> = {};
|
|
24
25
|
const warnings: Record<string, Error> = {};
|
|
@@ -26,51 +27,61 @@ export const getTransactionStatus = async (
|
|
|
26
27
|
const reserveBaseXRP = parseAPIValue(
|
|
27
28
|
serverInfos.info.validated_ledger.reserve_base_xrp.toString(),
|
|
28
29
|
);
|
|
29
|
-
const estimatedFees =
|
|
30
|
-
const totalSpent =
|
|
31
|
-
const amount =
|
|
30
|
+
const estimatedFees = transactionIntent.fees || 0n;
|
|
31
|
+
const totalSpent = transactionIntent.amount + estimatedFees;
|
|
32
|
+
const amount = transactionIntent.amount;
|
|
32
33
|
|
|
33
34
|
if (amount > 0 && estimatedFees * 10n > amount) {
|
|
34
35
|
warnings.feeTooHigh = new FeeTooHigh();
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
const balances = await getBalance(transactionIntent.sender);
|
|
39
|
+
const nativeBalance = balances.find(b => b.asset.type === "native");
|
|
40
|
+
if (nativeBalance === undefined) {
|
|
41
|
+
throw Error("Shouldn't happen");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!transactionIntent.fees) {
|
|
38
45
|
errors.fee = new FeeNotLoaded();
|
|
39
|
-
} else if (
|
|
46
|
+
} else if (transactionIntent.fees === 0n) {
|
|
40
47
|
errors.fee = new FeeRequired();
|
|
41
|
-
} else if (totalSpent >
|
|
48
|
+
} else if (totalSpent > nativeBalance.value - BigInt(reserveBaseXRP.toString())) {
|
|
42
49
|
errors.amount = new NotEnoughSpendableBalance("", {
|
|
43
|
-
minimumAmount:
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
50
|
+
minimumAmount: transactionIntent.asset.unit
|
|
51
|
+
? formatCurrencyUnit(transactionIntent.asset.unit, reserveBaseXRP, {
|
|
52
|
+
disableRounding: true,
|
|
53
|
+
useGrouping: false,
|
|
54
|
+
showCode: true,
|
|
55
|
+
})
|
|
56
|
+
: "Unknown unit",
|
|
48
57
|
});
|
|
49
58
|
} else if (
|
|
50
|
-
|
|
51
|
-
(await cachedRecipientIsNew(
|
|
52
|
-
|
|
59
|
+
transactionIntent.recipient &&
|
|
60
|
+
(await cachedRecipientIsNew(transactionIntent.recipient)) &&
|
|
61
|
+
transactionIntent.amount < BigInt(reserveBaseXRP.toString())
|
|
53
62
|
) {
|
|
54
63
|
errors.amount = new NotEnoughBalanceBecauseDestinationNotCreated("", {
|
|
55
|
-
minimalAmount:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
64
|
+
minimalAmount: transactionIntent.asset.unit
|
|
65
|
+
? formatCurrencyUnit(transactionIntent.asset.unit, reserveBaseXRP, {
|
|
66
|
+
disableRounding: true,
|
|
67
|
+
useGrouping: false,
|
|
68
|
+
showCode: true,
|
|
69
|
+
})
|
|
70
|
+
: "Unknown unit",
|
|
60
71
|
});
|
|
61
72
|
}
|
|
62
73
|
|
|
63
|
-
if (!
|
|
74
|
+
if (!transactionIntent.recipient) {
|
|
64
75
|
errors.recipient = new RecipientRequired("");
|
|
65
|
-
} else if (
|
|
76
|
+
} else if (transactionIntent.sender === transactionIntent.recipient) {
|
|
66
77
|
errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
|
|
67
|
-
} else if (!isValidClassicAddress(
|
|
78
|
+
} else if (!isValidClassicAddress(transactionIntent.recipient)) {
|
|
68
79
|
errors.recipient = new InvalidAddress("", {
|
|
69
|
-
currencyName:
|
|
80
|
+
currencyName: transactionIntent.asset.name ?? "",
|
|
70
81
|
});
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
if (!errors.amount && amount
|
|
84
|
+
if (!errors.amount && amount === 0n) {
|
|
74
85
|
errors.amount = new AmountRequired();
|
|
75
86
|
}
|
|
76
87
|
|
|
@@ -146,7 +146,7 @@ describe("listOperations", () => {
|
|
|
146
146
|
async ({ address, opSender, opDestination, expectedType }) => {
|
|
147
147
|
// Given
|
|
148
148
|
const deliveredAmount = 100;
|
|
149
|
-
const
|
|
149
|
+
const fees = 10;
|
|
150
150
|
mockNetworkGetTransactions.mockResolvedValue(
|
|
151
151
|
mockNetworkTxs([
|
|
152
152
|
{
|
|
@@ -156,7 +156,7 @@ describe("listOperations", () => {
|
|
|
156
156
|
meta: { delivered_amount: deliveredAmount.toString() },
|
|
157
157
|
tx_json: {
|
|
158
158
|
TransactionType: "Payment",
|
|
159
|
-
Fee:
|
|
159
|
+
Fee: fees.toString(),
|
|
160
160
|
ledger_index: 1,
|
|
161
161
|
date: 1000,
|
|
162
162
|
Account: opSender,
|
|
@@ -172,7 +172,7 @@ describe("listOperations", () => {
|
|
|
172
172
|
meta: { delivered_amount: deliveredAmount.toString() },
|
|
173
173
|
tx_json: {
|
|
174
174
|
TransactionType: "Payment",
|
|
175
|
-
Fee:
|
|
175
|
+
Fee: fees.toString(),
|
|
176
176
|
ledger_index: 1,
|
|
177
177
|
date: 1000,
|
|
178
178
|
Account: opSender,
|
|
@@ -189,7 +189,7 @@ describe("listOperations", () => {
|
|
|
189
189
|
meta: { delivered_amount: deliveredAmount.toString() },
|
|
190
190
|
tx_json: {
|
|
191
191
|
TransactionType: "Payment",
|
|
192
|
-
Fee:
|
|
192
|
+
Fee: fees.toString(),
|
|
193
193
|
ledger_index: 1,
|
|
194
194
|
date: 1000,
|
|
195
195
|
Account: opSender,
|
|
@@ -217,7 +217,7 @@ describe("listOperations", () => {
|
|
|
217
217
|
expect(mockNetworkGetTransactions).toHaveBeenCalledTimes(1);
|
|
218
218
|
// if expectedType is "OUT", compute value with fees (i.e. delivered_amount + Fee)
|
|
219
219
|
const expectedValue =
|
|
220
|
-
expectedType === "IN" ? BigInt(deliveredAmount) : BigInt(deliveredAmount +
|
|
220
|
+
expectedType === "IN" ? BigInt(deliveredAmount) : BigInt(deliveredAmount + fees);
|
|
221
221
|
expect(results).toEqual([
|
|
222
222
|
{
|
|
223
223
|
id: "HASH_VALUE",
|
|
@@ -125,10 +125,10 @@ const convertToCoreOperation =
|
|
|
125
125
|
? BigInt(delivered_amount)
|
|
126
126
|
: BigInt(0);
|
|
127
127
|
|
|
128
|
-
const
|
|
128
|
+
const fees = BigInt(Fee);
|
|
129
129
|
if (type === "OUT") {
|
|
130
|
-
if (!Number.isNaN(
|
|
131
|
-
value = value +
|
|
130
|
+
if (!Number.isNaN(fees)) {
|
|
131
|
+
value = value + fees;
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -170,7 +170,7 @@ const convertToCoreOperation =
|
|
|
170
170
|
asset: { type: "native" },
|
|
171
171
|
tx: {
|
|
172
172
|
hash: hash,
|
|
173
|
-
fees:
|
|
173
|
+
fees: fees,
|
|
174
174
|
date: new Date(toEpochDate),
|
|
175
175
|
block: {
|
|
176
176
|
time: new Date(close_time_iso),
|
|
@@ -184,7 +184,7 @@ const convertToCoreOperation =
|
|
|
184
184
|
recipients: [Destination],
|
|
185
185
|
};
|
|
186
186
|
|
|
187
|
-
if (Object.keys(details).length
|
|
187
|
+
if (Object.keys(details).length !== 0) {
|
|
188
188
|
op = {
|
|
189
189
|
...op,
|
|
190
190
|
details,
|
|
@@ -40,7 +40,7 @@ export const dataset: DatasetTest<Transaction> = {
|
|
|
40
40
|
recipient: "rB6pwovsyrFWhPYUsjj9V3CHck985QjiXi",
|
|
41
41
|
amount: "15000000",
|
|
42
42
|
tag: null,
|
|
43
|
-
|
|
43
|
+
fees: "1",
|
|
44
44
|
feeCustomUnit: null,
|
|
45
45
|
networkInfo: null,
|
|
46
46
|
}),
|
|
@@ -75,7 +75,7 @@ export const dataset: DatasetTest<Transaction> = {
|
|
|
75
75
|
recipient: newAddress1,
|
|
76
76
|
amount: "10000000",
|
|
77
77
|
tag: null,
|
|
78
|
-
|
|
78
|
+
fees: "1",
|
|
79
79
|
feeCustomUnit: null,
|
|
80
80
|
networkInfo: null
|
|
81
81
|
}),
|
|
@@ -97,7 +97,7 @@ export const dataset: DatasetTest<Transaction> = {
|
|
|
97
97
|
recipient: "rageXHB6Q4VbvvWdTzKANwjeCT4HXFCKX7",
|
|
98
98
|
amount: "10000000",
|
|
99
99
|
tag: null,
|
|
100
|
-
|
|
100
|
+
fees: "10", // NOTE: fee is not customizable, this field is ignored
|
|
101
101
|
feeCustomUnit: null,
|
|
102
102
|
networkInfo: null,
|
|
103
103
|
}),
|
|
@@ -118,7 +118,7 @@ export const dataset: DatasetTest<Transaction> = {
|
|
|
118
118
|
recipient: "rB6pwovsyrFWhPYUsjj9V3CHck985QjiXi",
|
|
119
119
|
amount: "10000000",
|
|
120
120
|
tag: 12345,
|
|
121
|
-
|
|
121
|
+
fees: "10", // NOTE: fee is not customizable, this field is ignored
|
|
122
122
|
feeCustomUnit: null,
|
|
123
123
|
networkInfo: null,
|
|
124
124
|
}),
|
package/src/test/cli.ts
CHANGED
package/src/transaction.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
|
12
12
|
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies/index";
|
|
13
13
|
|
|
14
14
|
export const formatTransaction = (
|
|
15
|
-
{ amount, recipient,
|
|
15
|
+
{ amount, recipient, fees, tag, useAllAmount }: Transaction,
|
|
16
16
|
account: Account,
|
|
17
17
|
): string => `
|
|
18
18
|
SEND ${
|
|
@@ -25,9 +25,9 @@ SEND ${
|
|
|
25
25
|
}
|
|
26
26
|
TO ${recipient}
|
|
27
27
|
with fee=${
|
|
28
|
-
!
|
|
28
|
+
!fees
|
|
29
29
|
? "?"
|
|
30
|
-
: formatCurrencyUnit(getAccountCurrency(account).units[0],
|
|
30
|
+
: formatCurrencyUnit(getAccountCurrency(account).units[0], fees, {
|
|
31
31
|
showCode: true,
|
|
32
32
|
disableRounding: true,
|
|
33
33
|
})
|
|
@@ -40,7 +40,7 @@ export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
|
40
40
|
...common,
|
|
41
41
|
family: tr.family,
|
|
42
42
|
tag: tr.tag,
|
|
43
|
-
|
|
43
|
+
fees: tr.fees ? new BigNumber(tr.fees) : null,
|
|
44
44
|
feeCustomUnit: tr.feeCustomUnit,
|
|
45
45
|
// 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)
|
|
46
46
|
networkInfo: networkInfo && {
|
|
@@ -58,7 +58,7 @@ export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
|
58
58
|
...common,
|
|
59
59
|
family: t.family,
|
|
60
60
|
tag: t.tag,
|
|
61
|
-
|
|
61
|
+
fees: t.fees ? t.fees.toString() : null,
|
|
62
62
|
feeCustomUnit: t.feeCustomUnit,
|
|
63
63
|
// 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)
|
|
64
64
|
networkInfo: networkInfo && {
|
package/src/types/bridge.ts
CHANGED
|
@@ -21,7 +21,7 @@ export type NetworkInfoRaw = {
|
|
|
21
21
|
|
|
22
22
|
export type Transaction = TransactionCommon & {
|
|
23
23
|
family: "xrp";
|
|
24
|
-
|
|
24
|
+
fees: BigNumber | null | undefined;
|
|
25
25
|
networkInfo: NetworkInfo | null | undefined;
|
|
26
26
|
tag: number | null | undefined;
|
|
27
27
|
feeCustomUnit: Unit | null | undefined;
|
|
@@ -29,7 +29,7 @@ export type Transaction = TransactionCommon & {
|
|
|
29
29
|
|
|
30
30
|
export type TransactionRaw = TransactionCommonRaw & {
|
|
31
31
|
family: "xrp";
|
|
32
|
-
|
|
32
|
+
fees: string | null | undefined;
|
|
33
33
|
networkInfo: NetworkInfoRaw | null | undefined;
|
|
34
34
|
tag: number | null | undefined;
|
|
35
35
|
feeCustomUnit: Unit | null | undefined;
|