Skip to content

Commit

Permalink
Merge pull request #8961 from LedgerHQ/bugfix/LIVE-15822
Browse files Browse the repository at this point in the history
fix(wallet-api): add missing cosmos walletApiAdapter [LIVE-15822]
  • Loading branch information
Justkant authored Jan 22, 2025
2 parents 694e041 + 5dda064 commit 3acdc27
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/silent-poets-check.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": minor
---

fix(wallet-api): add missing cosmos walletApiAdapter
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = `
[
{
"balance": "1612686",
"balance": "5739320",
"currencyId": "cosmos",
"derivationMode": "",
"freshAddress": "cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl",
Expand All @@ -12,7 +12,7 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 1`] = `
"index": 0,
"pendingOperations": [],
"seedIdentifier": "0388459b2653519948b12492f1a0b464720110c147a8155d23d423a5cc3c21d89a",
"spendableBalance": "315704",
"spendableBalance": "4442338",
"swapHistory": [],
"syncHash": undefined,
"used": true,
Expand Down Expand Up @@ -258,6 +258,25 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 2`] = `
"type": "IN",
"value": "1000",
},
{
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
"blockHash": null,
"blockHeight": 24046706,
"extra": {},
"fee": "1729",
"hasFailed": false,
"hash": "146D033842F4637F5FA2F13AC4D7888EEA8935F1D5822B955562ED685E7E8A78",
"id": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:-146D033842F4637F5FA2F13AC4D7888EEA8935F1D5822B955562ED685E7E8A78-IN",
"recipients": [
"cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl",
],
"senders": [
"cosmos125me68y8fx88wyqwa4mp4q2cmglrnetsa2kr68",
],
"transactionSequenceNumber": 22364,
"type": "IN",
"value": "4639888",
},
{
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
"blockHash": null,
Expand Down Expand Up @@ -1140,6 +1159,29 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 2`] = `
"type": "DELEGATE",
"value": "10650",
},
{
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
"blockHash": null,
"blockHeight": 23976580,
"extra": {
"memo": "LedgerLiveBot",
"validators": [
{
"address": "cosmosvaloper1clpqr4nrk4khgkxj78fcwwh6dl3uw4epsluffn",
"amount": "5210",
},
],
},
"fee": "17390",
"hasFailed": false,
"hash": "7706B2098FBB961FED169FE177276EFE1C85C7FCA216B61A9F9FD54DEDD6B81A",
"id": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:-7706B2098FBB961FED169FE177276EFE1C85C7FCA216B61A9F9FD54DEDD6B81A-REWARD",
"recipients": [],
"senders": [],
"transactionSequenceNumber": 157,
"type": "REWARD",
"value": "5210",
},
{
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
"blockHash": null,
Expand Down Expand Up @@ -2181,6 +2223,25 @@ exports[`cosmos currency bridge scanAccounts cosmos seed 1 2`] = `
"type": "DELEGATE",
"value": "11254",
},
{
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
"blockHash": null,
"blockHeight": 24063617,
"extra": {},
"fee": "1074",
"hasFailed": false,
"hash": "CEF4B772F7E12B048A8903146DDC06FB769813B0A6AB475EC455CE6BBAF9BAEB",
"id": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:-CEF4B772F7E12B048A8903146DDC06FB769813B0A6AB475EC455CE6BBAF9BAEB-OUT",
"recipients": [
"osmo10a3k4hvk37cc4hnxctw4p95fhscd2z6h2rmx0aukc6rm8u9qqx9smfsh7u",
],
"senders": [
"cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl",
],
"transactionSequenceNumber": 158,
"type": "OUT",
"value": "501074",
},
{
"accountId": "js:2:cosmos:cosmos1g84934jpu3v5de5yqukkkhxmcvsw3u2ajxvpdl:",
"blockHash": null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { Account } from "@ledgerhq/types-live";
import { CosmosTransaction as WalletAPICosmosTransaction } from "@ledgerhq/wallet-api-core";
import BigNumber from "bignumber.js";
import { Transaction } from "@ledgerhq/coin-cosmos/types/index";
import cosmos from "./walletApiAdapter";

describe("getWalletAPITransactionSignFlowInfos", () => {
describe("should properly get infos for Cosmos platform tx", () => {
it("without fees provided", () => {
const cosmosPlatformTx: WalletAPICosmosTransaction = {
family: "cosmos",
amount: new BigNumber(100000),
recipient: "0xABCDEF",
mode: "send",
};

const expectedLiveTx: Partial<Transaction> = {
...cosmosPlatformTx,
fees: null,
gas: null,
useAllAmount: false,
networkInfo: null,
memo: null,
sourceValidator: null,
validators: [],
};

const { canEditFees, hasFeesProvided, liveTx } = cosmos.getWalletAPITransactionSignFlowInfos({
walletApiTransaction: cosmosPlatformTx,
account: {} as Account,
});

expect(canEditFees).toBe(true);

expect(hasFeesProvided).toBe(false);

expect(liveTx).toEqual(expectedLiveTx);
});

it("with fees provided", () => {
const cosmosPlatformTx: WalletAPICosmosTransaction = {
family: "cosmos",
amount: new BigNumber(100000),
recipient: "0xABCDEF",
fees: new BigNumber(300),
mode: "send",
};

const expectedLiveTx: Partial<Transaction> = {
...cosmosPlatformTx,
gas: null,
useAllAmount: false,
networkInfo: null,
memo: null,
sourceValidator: null,
validators: [],
};

const { canEditFees, hasFeesProvided, liveTx } = cosmos.getWalletAPITransactionSignFlowInfos({
walletApiTransaction: cosmosPlatformTx,
account: {} as Account,
});

expect(canEditFees).toBe(true);

expect(hasFeesProvided).toBe(true);

expect(liveTx).toEqual(expectedLiveTx);
});
});
});
66 changes: 66 additions & 0 deletions libs/ledger-live-common/src/families/cosmos/walletApiAdapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import createTransaction from "@ledgerhq/coin-cosmos/createTransaction";
import { CosmosTransaction as WalletAPICosmosTransaction } from "@ledgerhq/wallet-api-core";
import {
AreFeesProvided,
ConvertToLiveTransaction,
GetWalletAPITransactionSignFlowInfos,
} from "../../wallet-api/types";
import { Transaction } from "@ledgerhq/coin-cosmos/types/index";

const CAN_EDIT_FEES = true;

const areFeesProvided: AreFeesProvided<WalletAPICosmosTransaction> = tx => !!tx.fees;

const convertToLiveTransaction: ConvertToLiveTransaction<
WalletAPICosmosTransaction,
Transaction
> = ({ account, walletApiTransaction }) => {
const liveTx: Transaction = createTransaction(account);

if (walletApiTransaction.amount) {
liveTx.amount = walletApiTransaction.amount;
}

if (walletApiTransaction.recipient) {
liveTx.recipient = walletApiTransaction.recipient;
}

if (walletApiTransaction.mode) {
liveTx.mode = walletApiTransaction.mode;
}

if (walletApiTransaction.fees) {
liveTx.fees = walletApiTransaction.fees;
}

if (walletApiTransaction.gas) {
liveTx.gas = walletApiTransaction.gas;
}

if (walletApiTransaction.memo) {
liveTx.memo = walletApiTransaction.memo;
}

if (walletApiTransaction.sourceValidator) {
liveTx.sourceValidator = walletApiTransaction.sourceValidator;
}

if (walletApiTransaction.validators) {
liveTx.validators = walletApiTransaction.validators;
}

return liveTx;
};

const getWalletAPITransactionSignFlowInfos: GetWalletAPITransactionSignFlowInfos<
WalletAPICosmosTransaction,
Transaction
> = ({ walletApiTransaction, account }) => {
return {
canEditFees: CAN_EDIT_FEES,
liveTx: convertToLiveTransaction({ walletApiTransaction, account }),
hasFeesProvided: areFeesProvided(walletApiTransaction),
};
};

export default { getWalletAPITransactionSignFlowInfos };
2 changes: 2 additions & 0 deletions libs/ledger-live-common/src/generated/walletApiAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import bitcoin from "../families/bitcoin/walletApiAdapter";
import cosmos from "../families/cosmos/walletApiAdapter";
import evm from "../families/evm/walletApiAdapter";
import polkadot from "../families/polkadot/walletApiAdapter";
import xrp from "../families/xrp/walletApiAdapter";

export default {
bitcoin,
cosmos,
evm,
polkadot,
xrp,
Expand Down

0 comments on commit 3acdc27

Please sign in to comment.