@ledgerhq/live-common 21.24.0-beta.0 → 21.25.2

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.
Files changed (53) hide show
  1. package/lib/families/crypto_org/deviceTransactionConfig.d.ts +11 -0
  2. package/lib/families/crypto_org/deviceTransactionConfig.d.ts.map +1 -0
  3. package/lib/families/crypto_org/deviceTransactionConfig.js +40 -0
  4. package/lib/families/crypto_org/deviceTransactionConfig.js.map +1 -0
  5. package/lib/families/ethereum/modules/compound.d.ts.map +1 -1
  6. package/lib/families/ethereum/modules/compound.js +2 -1
  7. package/lib/families/ethereum/modules/compound.js.map +1 -1
  8. package/lib/families/ethereum/modules/erc1155.d.ts.map +1 -1
  9. package/lib/families/ethereum/modules/erc1155.js +2 -1
  10. package/lib/families/ethereum/modules/erc1155.js.map +1 -1
  11. package/lib/families/ethereum/modules/erc20.d.ts.map +1 -1
  12. package/lib/families/ethereum/modules/erc20.js +2 -1
  13. package/lib/families/ethereum/modules/erc20.js.map +1 -1
  14. package/lib/families/ethereum/modules/erc721.d.ts.map +1 -1
  15. package/lib/families/ethereum/modules/erc721.js +2 -1
  16. package/lib/families/ethereum/modules/erc721.js.map +1 -1
  17. package/lib/families/ethereum/modules/index.d.ts +5 -0
  18. package/lib/families/ethereum/modules/index.d.ts.map +1 -1
  19. package/lib/families/ethereum/modules/index.js.map +1 -1
  20. package/lib/families/ethereum/signOperation.d.ts.map +1 -1
  21. package/lib/families/ethereum/signOperation.js +33 -24
  22. package/lib/families/ethereum/signOperation.js.map +1 -1
  23. package/lib/families/polkadot/address.d.ts.map +1 -1
  24. package/lib/families/polkadot/address.js +5 -1
  25. package/lib/families/polkadot/address.js.map +1 -1
  26. package/lib/families/polkadot/js-getTransactionStatus.d.ts.map +1 -1
  27. package/lib/families/polkadot/js-getTransactionStatus.js +6 -2
  28. package/lib/families/polkadot/js-getTransactionStatus.js.map +1 -1
  29. package/lib/families/tezos/bridge/js.d.ts.map +1 -1
  30. package/lib/families/tezos/bridge/js.js +32 -16
  31. package/lib/families/tezos/bridge/js.js.map +1 -1
  32. package/lib/generated/deviceTransactionConfig.d.ts +2 -0
  33. package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
  34. package/lib/generated/deviceTransactionConfig.js +18 -16
  35. package/lib/generated/deviceTransactionConfig.js.map +1 -1
  36. package/lib/hw/actions/transaction.d.ts +3 -1
  37. package/lib/hw/actions/transaction.d.ts.map +1 -1
  38. package/lib/hw/actions/transaction.js +4 -2
  39. package/lib/hw/actions/transaction.js.map +1 -1
  40. package/package.json +8 -8
  41. package/src/__tests__/__snapshots__/all.libcore.ts.snap +7 -7
  42. package/src/families/crypto_org/deviceTransactionConfig.ts +52 -0
  43. package/src/families/ethereum/modules/compound.ts +2 -0
  44. package/src/families/ethereum/modules/erc1155.ts +2 -0
  45. package/src/families/ethereum/modules/erc20.ts +2 -0
  46. package/src/families/ethereum/modules/erc721.ts +2 -0
  47. package/src/families/ethereum/modules/index.ts +10 -0
  48. package/src/families/ethereum/signOperation.ts +27 -8
  49. package/src/families/polkadot/address.ts +8 -2
  50. package/src/families/polkadot/js-getTransactionStatus.ts +6 -2
  51. package/src/families/tezos/bridge/js.ts +38 -17
  52. package/src/generated/deviceTransactionConfig.ts +3 -0
  53. package/src/hw/actions/transaction.ts +7 -2
@@ -58,7 +58,9 @@ const getSendTransactionStatus = async (
58
58
  } else if (a.freshAddress === t.recipient) {
59
59
  errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
60
60
  } else if (!isValidAddress(t.recipient)) {
61
- errors.recipient = new InvalidAddress("");
61
+ errors.recipient = new InvalidAddress("", {
62
+ currencyName: a.currency.name,
63
+ });
62
64
  }
63
65
 
64
66
  const estimatedFees = t.fees || new BigNumber(0);
@@ -181,7 +183,9 @@ const getTransactionStatus = async (a: Account, t: Transaction) => {
181
183
  if (!t.recipient) {
182
184
  errors.recipient = new RecipientRequired("");
183
185
  } else if (!isValidAddress(t.recipient)) {
184
- errors.recipient = new InvalidAddress("");
186
+ errors.recipient = new InvalidAddress("", {
187
+ currencyName: a.currency.name,
188
+ });
185
189
  } else if (await isControllerAddress(t.recipient)) {
186
190
  errors.recipient = new PolkadotUnauthorizedOperation(
187
191
  "Recipient is already a controller"
@@ -182,11 +182,14 @@ const prepareTransaction = async (
182
182
  },
183
183
  });
184
184
 
185
+ const t: Transaction = { ...transaction, taquitoError: null };
186
+
187
+ let amount = transaction.amount;
185
188
  if (transaction.useAllAmount) {
186
189
  // taquito does not accept 0, so we do 1
187
190
  // only failing case is when the account precisely has fees + 1. which is
188
191
  // unlikely
189
- transaction.amount = new BigNumber(1);
192
+ amount = new BigNumber(1);
190
193
  }
191
194
 
192
195
  try {
@@ -196,7 +199,7 @@ const prepareTransaction = async (
196
199
  out = await tezos.estimate.transfer({
197
200
  mutez: true,
198
201
  to: transaction.recipient,
199
- amount: transaction.amount.toNumber(),
202
+ amount: amount.toNumber(),
200
203
  });
201
204
  break;
202
205
  case "delegate":
@@ -214,7 +217,7 @@ const prepareTransaction = async (
214
217
  throw new Error("unsupported mode=" + transaction.mode);
215
218
  }
216
219
 
217
- if (transaction.useAllAmount) {
220
+ if (t.useAllAmount) {
218
221
  const totalFees = out.suggestedFeeMutez + out.burnFeeMutez;
219
222
  const maxAmount = account.balance
220
223
  .minus(totalFees + (tezosResources.revealed ? 0 : DEFAULT_FEE.REVEAL))
@@ -228,41 +231,59 @@ const prepareTransaction = async (
228
231
  return gasBuffer * MINIMAL_FEE_PER_GAS_MUTEZ + opSize;
229
232
  };
230
233
  const incr = increasedFee(gasBuffer, Number(out.opSize));
231
- transaction.fees = new BigNumber(out.suggestedFeeMutez + incr);
232
- transaction.gasLimit = new BigNumber(out.gasLimit + gasBuffer);
233
- transaction.amount = new BigNumber(maxAmount - incr);
234
+ t.fees = new BigNumber(out.suggestedFeeMutez + incr);
235
+ t.gasLimit = new BigNumber(out.gasLimit + gasBuffer);
236
+ t.amount = new BigNumber(maxAmount - incr);
234
237
  } else {
235
- transaction.fees = new BigNumber(out.suggestedFeeMutez);
236
- transaction.gasLimit = new BigNumber(out.gasLimit);
237
- transaction.storageLimit = new BigNumber(out.storageLimit);
238
+ t.fees = new BigNumber(out.suggestedFeeMutez);
239
+ t.gasLimit = new BigNumber(out.gasLimit);
240
+ t.storageLimit = new BigNumber(out.storageLimit);
238
241
  }
239
242
 
240
- transaction.storageLimit = new BigNumber(out.storageLimit);
241
- transaction.estimatedFees = transaction.fees;
243
+ t.storageLimit = new BigNumber(out.storageLimit);
244
+ t.estimatedFees = t.fees;
242
245
  if (!tezosResources.revealed) {
243
- transaction.estimatedFees = transaction.estimatedFees.plus(
244
- DEFAULT_FEE.REVEAL
245
- );
246
+ t.estimatedFees = t.estimatedFees.plus(DEFAULT_FEE.REVEAL);
246
247
  }
247
248
  } catch (e) {
248
249
  if (typeof e !== "object" || !e) throw e;
249
250
  if ("id" in e) {
250
- transaction.taquitoError = (e as { id: string }).id;
251
+ t.taquitoError = (e as { id: string }).id;
251
252
  } else if ("status" in e) {
252
253
  // in case of http 400, log & ignore (more case to handle)
253
254
  log(
254
255
  "taquito-network-error",
255
256
  String((e as { message: string }).message || ""),
256
- { transaction }
257
+ { transaction: t }
257
258
  );
258
259
  } else {
259
260
  throw e;
260
261
  }
261
262
  }
262
263
 
263
- return transaction;
264
+ // nothing changed
265
+ if (
266
+ bnEq(t.fees, transaction.fees) &&
267
+ bnEq(t.fees, transaction.fees) &&
268
+ bnEq(t.gasLimit, transaction.gasLimit) &&
269
+ bnEq(t.amount, transaction.amount) &&
270
+ bnEq(t.storageLimit, transaction.storageLimit) &&
271
+ bnEq(t.estimatedFees, transaction.estimatedFees) &&
272
+ t.taquitoError === transaction.taquitoError
273
+ ) {
274
+ return transaction;
275
+ }
276
+
277
+ return t;
264
278
  };
265
279
 
280
+ function bnEq(
281
+ a: BigNumber | null | undefined,
282
+ b: BigNumber | null | undefined
283
+ ): boolean {
284
+ return !a && !b ? true : !a || !b ? false : a.eq(b);
285
+ }
286
+
266
287
  const estimateMaxSpendable = async ({
267
288
  account,
268
289
  parentAccount,
@@ -4,6 +4,8 @@ import bitcoin from "../families/bitcoin/deviceTransactionConfig";
4
4
 
5
5
  import cosmos from "../families/cosmos/deviceTransactionConfig";
6
6
 
7
+ import crypto_org from "../families/crypto_org/deviceTransactionConfig";
8
+
7
9
  import elrond from "../families/elrond/deviceTransactionConfig";
8
10
 
9
11
  import ethereum from "../families/ethereum/deviceTransactionConfig";
@@ -25,6 +27,7 @@ export default {
25
27
  algorand,
26
28
  bitcoin,
27
29
  cosmos,
30
+ crypto_org,
28
31
  elrond,
29
32
  ethereum,
30
33
  polkadot,
@@ -17,7 +17,7 @@ import { getMainAccount } from "../../account";
17
17
  import { getAccountBridge } from "../../bridge";
18
18
  import type { ConnectAppEvent, Input as ConnectAppInput } from "../connectApp";
19
19
  import type { Action, Device } from "./types";
20
- import type { AppState } from "./app";
20
+ import type { AppRequest, AppState } from "./app";
21
21
  import { createAction as createAppAction } from "./app";
22
22
  type State = {
23
23
  signedOperation: SignedOperation | null | undefined;
@@ -33,6 +33,8 @@ type TransactionRequest = {
33
33
  transaction: Transaction;
34
34
  status: TransactionStatus;
35
35
  appName?: string;
36
+ dependencies?: AppRequest[];
37
+ requireLatestFirmware?: boolean;
36
38
  };
37
39
  type TransactionResult =
38
40
  | {
@@ -112,7 +114,8 @@ export const createAction = (
112
114
  reduxDevice: Device | null | undefined,
113
115
  txRequest: TransactionRequest
114
116
  ): TransactionState => {
115
- const { transaction, appName } = txRequest;
117
+ const { transaction, appName, dependencies, requireLatestFirmware } =
118
+ txRequest;
116
119
  const mainAccount = getMainAccount(
117
120
  txRequest.account,
118
121
  txRequest.parentAccount
@@ -120,6 +123,8 @@ export const createAction = (
120
123
  const appState = createAppAction(connectAppExec).useHook(reduxDevice, {
121
124
  account: mainAccount,
122
125
  appName,
126
+ dependencies,
127
+ requireLatestFirmware,
123
128
  });
124
129
  const { device, opened, inWrongDeviceForAccount, error } = appState;
125
130
  const [state, setState] = useState(initialState);