Skip to content

Commit 3acdc27

Browse files
authored
Merge pull request #8961 from LedgerHQ/bugfix/LIVE-15822
fix(wallet-api): add missing cosmos walletApiAdapter [LIVE-15822]
2 parents 694e041 + 5dda064 commit 3acdc27

File tree

5 files changed

+207
-2
lines changed

5 files changed

+207
-2
lines changed

.changeset/silent-poets-check.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ledgerhq/live-common": minor
3+
---
4+
5+
fix(wallet-api): add missing cosmos walletApiAdapter

libs/ledger-live-common/src/families/cosmos/datasets/__snapshots__/cosmos.integration.test.ts.snap

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = `
44
[
55
{
6-
"balance": "1612686",
6+
"balance": "5739320",
77
"currencyId": "cosmos",
88
"derivationMode": "",
99
"freshAddress": "cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl",
@@ -12,7 +12,7 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = `
1212
"index": 0,
1313
"pendingOperations": [],
1414
"seedIdentifier": "0388459b2653519948b12492f1a0b464720110c147a8155d23d423a5cc3c21d89a",
15-
"spendableBalance": "315704",
15+
"spendableBalance": "4442338",
1616
"swapHistory": [],
1717
"syncHash": undefined,
1818
"used": true,
@@ -258,6 +258,25 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 2`] = `
258258
"type": "IN",
259259
"value": "1000",
260260
},
261+
{
262+
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
263+
"blockHash": null,
264+
"blockHeight": 24046706,
265+
"extra": {},
266+
"fee": "1729",
267+
"hasFailed": false,
268+
"hash": "146D033842F4637F5FA2F13AC4D7888EEA8935F1D5822B955562ED685E7E8A78",
269+
"id": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:-146D033842F4637F5FA2F13AC4D7888EEA8935F1D5822B955562ED685E7E8A78-IN",
270+
"recipients": [
271+
"cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl",
272+
],
273+
"senders": [
274+
"cosmos125me68y8fx88wyqwa4mp4q2cmglrnetsa2kr68",
275+
],
276+
"transactionSequenceNumber": 22364,
277+
"type": "IN",
278+
"value": "4639888",
279+
},
261280
{
262281
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
263282
"blockHash": null,
@@ -1140,6 +1159,29 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 2`] = `
11401159
"type": "DELEGATE",
11411160
"value": "10650",
11421161
},
1162+
{
1163+
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
1164+
"blockHash": null,
1165+
"blockHeight": 23976580,
1166+
"extra": {
1167+
"memo": "LedgerLiveBot",
1168+
"validators": [
1169+
{
1170+
"address": "cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn",
1171+
"amount": "5210",
1172+
},
1173+
],
1174+
},
1175+
"fee": "17390",
1176+
"hasFailed": false,
1177+
"hash": "7706B2098FBB961FED169FE177276EFE1C85C7FCA216B61A9F9FD54DEDD6B81A",
1178+
"id": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:-7706B2098FBB961FED169FE177276EFE1C85C7FCA216B61A9F9FD54DEDD6B81A-REWARD",
1179+
"recipients": [],
1180+
"senders": [],
1181+
"transactionSequenceNumber": 157,
1182+
"type": "REWARD",
1183+
"value": "5210",
1184+
},
11431185
{
11441186
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
11451187
"blockHash": null,
@@ -2181,6 +2223,25 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 2`] = `
21812223
"type": "DELEGATE",
21822224
"value": "11254",
21832225
},
2226+
{
2227+
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
2228+
"blockHash": null,
2229+
"blockHeight": 24063617,
2230+
"extra": {},
2231+
"fee": "1074",
2232+
"hasFailed": false,
2233+
"hash": "CEF4B772F7E12B048A8903146DDC06FB769813B0A6AB475EC455CE6BBAF9BAEB",
2234+
"id": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:-CEF4B772F7E12B048A8903146DDC06FB769813B0A6AB475EC455CE6BBAF9BAEB-OUT",
2235+
"recipients": [
2236+
"osmo10a3k4hvk37cc4hnxctw4p95fhscd2z6h2rmx0aukc6rm8u9qqx9smfsh7u",
2237+
],
2238+
"senders": [
2239+
"cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl",
2240+
],
2241+
"transactionSequenceNumber": 158,
2242+
"type": "OUT",
2243+
"value": "501074",
2244+
},
21842245
{
21852246
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
21862247
"blockHash": null,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { Account } from "@ledgerhq/types-live";
2+
import { CosmosTransaction as WalletAPICosmosTransaction } from "@ledgerhq/wallet-api-core";
3+
import BigNumber from "bignumber.js";
4+
import { Transaction } from "@ledgerhq/coin-cosmos/types/index";
5+
import cosmos from "./walletApiAdapter";
6+
7+
describe("getWalletAPITransactionSignFlowInfos", () => {
8+
describe("should properly get infos for Cosmos platform tx", () => {
9+
it("without fees provided", () => {
10+
const cosmosPlatformTx: WalletAPICosmosTransaction = {
11+
family: "cosmos",
12+
amount: new BigNumber(100000),
13+
recipient: "0xABCDEF",
14+
mode: "send",
15+
};
16+
17+
const expectedLiveTx: Partial<Transaction> = {
18+
...cosmosPlatformTx,
19+
fees: null,
20+
gas: null,
21+
useAllAmount: false,
22+
networkInfo: null,
23+
memo: null,
24+
sourceValidator: null,
25+
validators: [],
26+
};
27+
28+
const { canEditFees, hasFeesProvided, liveTx } = cosmos.getWalletAPITransactionSignFlowInfos({
29+
walletApiTransaction: cosmosPlatformTx,
30+
account: {} as Account,
31+
});
32+
33+
expect(canEditFees).toBe(true);
34+
35+
expect(hasFeesProvided).toBe(false);
36+
37+
expect(liveTx).toEqual(expectedLiveTx);
38+
});
39+
40+
it("with fees provided", () => {
41+
const cosmosPlatformTx: WalletAPICosmosTransaction = {
42+
family: "cosmos",
43+
amount: new BigNumber(100000),
44+
recipient: "0xABCDEF",
45+
fees: new BigNumber(300),
46+
mode: "send",
47+
};
48+
49+
const expectedLiveTx: Partial<Transaction> = {
50+
...cosmosPlatformTx,
51+
gas: null,
52+
useAllAmount: false,
53+
networkInfo: null,
54+
memo: null,
55+
sourceValidator: null,
56+
validators: [],
57+
};
58+
59+
const { canEditFees, hasFeesProvided, liveTx } = cosmos.getWalletAPITransactionSignFlowInfos({
60+
walletApiTransaction: cosmosPlatformTx,
61+
account: {} as Account,
62+
});
63+
64+
expect(canEditFees).toBe(true);
65+
66+
expect(hasFeesProvided).toBe(true);
67+
68+
expect(liveTx).toEqual(expectedLiveTx);
69+
});
70+
});
71+
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import createTransaction from "@ledgerhq/coin-cosmos/createTransaction";
2+
import { CosmosTransaction as WalletAPICosmosTransaction } from "@ledgerhq/wallet-api-core";
3+
import {
4+
AreFeesProvided,
5+
ConvertToLiveTransaction,
6+
GetWalletAPITransactionSignFlowInfos,
7+
} from "../../wallet-api/types";
8+
import { Transaction } from "@ledgerhq/coin-cosmos/types/index";
9+
10+
const CAN_EDIT_FEES = true;
11+
12+
const areFeesProvided: AreFeesProvided<WalletAPICosmosTransaction> = tx => !!tx.fees;
13+
14+
const convertToLiveTransaction: ConvertToLiveTransaction<
15+
WalletAPICosmosTransaction,
16+
Transaction
17+
> = ({ account, walletApiTransaction }) => {
18+
const liveTx: Transaction = createTransaction(account);
19+
20+
if (walletApiTransaction.amount) {
21+
liveTx.amount = walletApiTransaction.amount;
22+
}
23+
24+
if (walletApiTransaction.recipient) {
25+
liveTx.recipient = walletApiTransaction.recipient;
26+
}
27+
28+
if (walletApiTransaction.mode) {
29+
liveTx.mode = walletApiTransaction.mode;
30+
}
31+
32+
if (walletApiTransaction.fees) {
33+
liveTx.fees = walletApiTransaction.fees;
34+
}
35+
36+
if (walletApiTransaction.gas) {
37+
liveTx.gas = walletApiTransaction.gas;
38+
}
39+
40+
if (walletApiTransaction.memo) {
41+
liveTx.memo = walletApiTransaction.memo;
42+
}
43+
44+
if (walletApiTransaction.sourceValidator) {
45+
liveTx.sourceValidator = walletApiTransaction.sourceValidator;
46+
}
47+
48+
if (walletApiTransaction.validators) {
49+
liveTx.validators = walletApiTransaction.validators;
50+
}
51+
52+
return liveTx;
53+
};
54+
55+
const getWalletAPITransactionSignFlowInfos: GetWalletAPITransactionSignFlowInfos<
56+
WalletAPICosmosTransaction,
57+
Transaction
58+
> = ({ walletApiTransaction, account }) => {
59+
return {
60+
canEditFees: CAN_EDIT_FEES,
61+
liveTx: convertToLiveTransaction({ walletApiTransaction, account }),
62+
hasFeesProvided: areFeesProvided(walletApiTransaction),
63+
};
64+
};
65+
66+
export default { getWalletAPITransactionSignFlowInfos };

libs/ledger-live-common/src/generated/walletApiAdapter.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import bitcoin from "../families/bitcoin/walletApiAdapter";
2+
import cosmos from "../families/cosmos/walletApiAdapter";
23
import evm from "../families/evm/walletApiAdapter";
34
import polkadot from "../families/polkadot/walletApiAdapter";
45
import xrp from "../families/xrp/walletApiAdapter";
56

67
export default {
78
bitcoin,
9+
cosmos,
810
evm,
911
polkadot,
1012
xrp,

0 commit comments

Comments
 (0)