Skip to content

Commit

Permalink
fix(wallet-api): ripple wrong family name [LIVE-12929]
Browse files Browse the repository at this point in the history
  • Loading branch information
Justkant committed Jun 10, 2024
1 parent 6e8a432 commit 09d3577
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-scissors-brush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

fix(wallet-api): ripple wrong family name
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"id": "ripple",
"ticker": "XRP",
"name": "XRP",
"family": "xrp",
"family": "ripple",
"color": "#27a2db",
"decimals": 6
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"id": "ripple",
"ticker": "XRP",
"name": "XRP",
"family": "xrp",
"family": "ripple",
"color": "#27a2db",
"decimals": 6
},
Expand Down
9 changes: 4 additions & 5 deletions libs/ledger-live-common/src/platform/converters.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { FAMILIES } from "@ledgerhq/live-app-sdk";
import { Account, AccountLike } from "@ledgerhq/types-live";
import { isTokenAccount } from "../account";
import byFamily from "../generated/platformAdapter";
import type { Transaction } from "../generated/types";
import {
FAMILIES_MAPPING_LL_TO_WAPI,
FAMILIES_MAPPING_WAPI_TO_LL,
PlatformAccount,
PlatformCurrency,
PlatformCurrencyType,
Expand Down Expand Up @@ -75,7 +76,7 @@ export function currencyToPlatformCurrency(currency: PlatformSupportedCurrency):
id: currency.id,
ticker: currency.ticker,
name: currency.name,
family: currency.family,
family: FAMILIES_MAPPING_LL_TO_WAPI[currency.family] ?? currency.family,
color: currency.color,
units: currency.units.map(unit => ({
name: unit.name,
Expand All @@ -92,9 +93,7 @@ export const getPlatformTransactionSignFlowInfos = (
hasFeesProvided: boolean;
liveTx: Partial<Transaction>;
} => {
// This is a hack to link WalletAPI "ethereum" family to new "evm" family
const isEthereumFamily = platformTx.family === FAMILIES.ETHEREUM;
const liveFamily = isEthereumFamily ? "evm" : platformTx.family;
const liveFamily = FAMILIES_MAPPING_WAPI_TO_LL[platformTx.family] ?? platformTx.family;

const familyModule = byFamily[liveFamily];

Expand Down
13 changes: 12 additions & 1 deletion libs/ledger-live-common/src/platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import {
FAMILIES,
} from "@ledgerhq/live-app-sdk";
import { z } from "zod";
import { reverseRecord } from "../wallet-api/helpers";

export const FAMILIES_MAPPING_WAPI_TO_LL = {
ethereum: "evm",
ripple: "xrp",
} as const;

export const FAMILIES_MAPPING_LL_TO_WAPI = reverseRecord(FAMILIES_MAPPING_WAPI_TO_LL);

/**
* this is a hack to add the "evm" family to the list of supported families of
Expand All @@ -15,7 +23,10 @@ import { z } from "zod";
* "ethereum" family, following the "ethereum" / "evm" families merge
* (and removal of the "ethereum" family)
*/
export const PLATFORM_FAMILIES = [...Object.values(FAMILIES), "evm", "xrp"];
export const PLATFORM_FAMILIES = [
...Object.values(FAMILIES),
...Object.values(FAMILIES_MAPPING_WAPI_TO_LL),
];

export { FAMILIES as PLATFORM_FAMILIES_ENUM };

Expand Down
10 changes: 9 additions & 1 deletion libs/ledger-live-common/src/wallet-api/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ import Fuse from "fuse.js";
import { AppManifest } from "../wallet-api/types";

import { FAMILIES } from "@ledgerhq/wallet-api-core";
import { reverseRecord } from "./helpers";

export const FAMILIES_MAPPING_WAPI_TO_LL = {
ethereum: "evm",
ripple: "xrp",
} as const;

export const FAMILIES_MAPPING_LL_TO_WAPI = reverseRecord(FAMILIES_MAPPING_WAPI_TO_LL);

/**
* FIXME
* This is not robust, we should have an explicit adapter between the wallet API currencies (families) and live currencies (families)
* For example here, the `ethereum` family on `wallet-api` should be mapped to the `evm` family on LL
*/
export const WALLET_API_FAMILIES = [...FAMILIES, "evm", "xrp"];
export const WALLET_API_FAMILIES = [...FAMILIES, ...Object.values(FAMILIES_MAPPING_WAPI_TO_LL)];

export const WALLET_API_VERSION = "2.0.0";

Expand Down
11 changes: 5 additions & 6 deletions libs/ledger-live-common/src/wallet-api/converters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Account, AccountLike } from "@ledgerhq/types-live";
import { v5 as uuidv5 } from "uuid";
import { WalletState, accountNameWithDefaultSelector } from "@ledgerhq/live-wallet/store";
import byFamily from "../generated/walletApiAdapter";
import type { Transaction } from "../generated/types";
import { isTokenAccount } from "../account";
Expand All @@ -10,8 +11,7 @@ import {
WalletAPISupportedCurrency,
GetWalletAPITransactionSignFlowInfos,
} from "./types";
import { Families } from "@ledgerhq/wallet-api-core";
import { WalletState, accountNameWithDefaultSelector } from "@ledgerhq/live-wallet/store";
import { FAMILIES_MAPPING_LL_TO_WAPI, FAMILIES_MAPPING_WAPI_TO_LL } from "./constants";

// The namespace is a randomly generated uuid v4 from https://www.uuidgenerator.net/
const NAMESPACE = "c3c78073-6844-409e-9e75-171ab4c7f9a2";
Expand Down Expand Up @@ -86,7 +86,7 @@ export function currencyToWalletAPICurrency(
id: currency.id,
ticker: currency.ticker,
name: currency.name,
family: currency.family === "evm" ? "ethereum" : (currency.family as Families),
family: FAMILIES_MAPPING_LL_TO_WAPI[currency.family] ?? currency.family,
color: currency.color,
decimals: currency.units[0].magnitude,
};
Expand All @@ -96,9 +96,8 @@ export const getWalletAPITransactionSignFlowInfos: GetWalletAPITransactionSignFl
WalletAPITransaction,
Transaction
> = ({ walletApiTransaction, account }) => {
// This is a hack to link WalletAPI "ethereum" family to new "evm" family
const isEthereumFamily = walletApiTransaction.family === "ethereum";
const liveFamily = isEthereumFamily ? "evm" : walletApiTransaction.family;
const liveFamily =
FAMILIES_MAPPING_WAPI_TO_LL[walletApiTransaction.family] ?? walletApiTransaction.family;

const familyModule = byFamily[liveFamily];

Expand Down
6 changes: 6 additions & 0 deletions libs/ledger-live-common/src/wallet-api/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,9 @@ export const stripHexPrefix = (str: string): string => {

return isHexPrefixed(str) ? str.slice(2) : str;
};

export function reverseRecord<T extends PropertyKey, U extends PropertyKey>(
input: Record<T, U>,
): Record<U, T> {
return Object.fromEntries(Object.entries(input).map(([key, value]) => [value, key]));
}

0 comments on commit 09d3577

Please sign in to comment.