-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8961 from LedgerHQ/bugfix/LIVE-15822
fix(wallet-api): add missing cosmos walletApiAdapter [LIVE-15822]
- Loading branch information
Showing
5 changed files
with
207 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
libs/ledger-live-common/src/families/cosmos/walletApiAdapter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
66
libs/ledger-live-common/src/families/cosmos/walletApiAdapter.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters