Skip to content

Commit

Permalink
bugfix: No cryptocurrency selection available in NFT gallery 'Add New' (
Browse files Browse the repository at this point in the history
#8668)

bugfix: No cryptocurrency selection available in NFT gallery 'Add New' flow except Ethereum
  • Loading branch information
mcayuelas-ledger authored Dec 23, 2024
1 parent 0db73a8 commit bd67aa1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/young-jeans-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": minor
---

Update groupCurrenciesByProvider to get Coins instead of token when it's relevant
19 changes: 17 additions & 2 deletions libs/ledger-live-common/src/deposit/deposit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { groupCurrenciesByProvider, searchByNameOrTicker, searchByProviderId } from "./helper";
import { MOCK } from "./mock";
import { MOCK, MOCK_POL } from "./mock";
import { MappedAsset } from "./type";
import { getTokenById } from "../currencies/index";
import { getCryptoCurrencyById, getTokenById } from "../currencies/index";

const MAPPED_ASSETS = MOCK as MappedAsset[];

Expand All @@ -25,5 +25,20 @@ describe("Deposit logic", () => {
currenciesByNetwork: currencies,
},
]);
const currenciesPol = MOCK_POL.map(asset =>
asset.$type === "Token"
? getTokenById(asset.ledgerId)
: getCryptoCurrencyById(asset.ledgerId),
);
const { currenciesByProvider: currenciesByProviderBis, sortedCryptoCurrencies } =
groupCurrenciesByProvider(MOCK_POL as MappedAsset[], currenciesPol);
expect(currenciesByProviderBis).toEqual([
{
providerId: "matic-network",
currenciesByNetwork: currenciesPol,
},
]);

expect(sortedCryptoCurrencies).toEqual([currenciesPol[1]]);
});
});
13 changes: 11 additions & 2 deletions libs/ledger-live-common/src/deposit/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,22 @@ export const groupCurrenciesByProvider = (
providerId: asset.providerId,
currenciesByNetwork: [ledgerCurrency],
});
// in this case, the first currency of the provider is the one we want to display
sortedCryptoCurrencies.push(ledgerCurrency);
} else {
existingEntry.currenciesByNetwork.push(ledgerCurrency);
}
}
}

// in this case, the first currency of the provider is the one we want to display (Wasn't true)
// So we need to take the first crypto or token currency of each provider to fix that
for (const [, { currenciesByNetwork }] of assetsByProviderId.entries()) {
const firstCrypto = currenciesByNetwork.find(c => c.type === "CryptoCurrency");
const elem = firstCrypto || currenciesByNetwork.find(c => c.type === "TokenCurrency");
if (elem) {
sortedCryptoCurrencies.push(elem);
}
}

return {
currenciesByProvider: Array.from(assetsByProviderId.values()),
sortedCryptoCurrencies,
Expand Down
46 changes: 46 additions & 0 deletions libs/ledger-live-common/src/deposit/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,49 @@ export const MOCK = [
ticker: "BSC-USD",
},
];

export const MOCK_POL = [
{
$type: "Token",
ledgerId: "bsc/bep20/matic_token",
providerId: "matic-network",
name: "Matic Token",
ticker: "MATIC",
network: "bsc",
contract: "0xcc42724c6683b7e57334c4e856f4c9965ed682bd",
status: "Ok",
reason: null,
data: {
img: "https://proxycgassets.api.live.ledger.com/coins/images/4713/large/polygon.png",
marketCapRank: 121,
},
},
{
$type: "Coin",
ledgerId: "polygon",
providerId: "matic-network",
name: "Polygon",
ticker: "POL",
status: "Ok",
reason: "Overridden",
data: {
img: "https://proxycgassets.api.live.ledger.com/coins/images/4713/large/polygon.png",
marketCapRank: 121,
},
},
{
$type: "Token",
ledgerId: "ethereum/erc20/matic",
providerId: "matic-network",
name: "Matic",
ticker: "MATIC",
network: "ethereum",
contract: "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",
status: "Ok",
reason: null,
data: {
img: "https://proxycgassets.api.live.ledger.com/coins/images/4713/large/polygon.png",
marketCapRank: 121,
},
},
];

0 comments on commit bd67aa1

Please sign in to comment.