Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

LIVE-1982-currency-initially-ordered #2513

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@ledgerhq/errors": "6.10.0",
"@ledgerhq/hw-transport": "6.27.1",
"@ledgerhq/hw-transport-http": "6.27.1",
"@ledgerhq/live-common": "22.1.0",
"@ledgerhq/live-common": "https://github.com/LedgerHQ/ledger-live-common.git#7108d9c61fe7cea9e660f9e9aa29a97df9b65c94",
"@ledgerhq/logs": "6.10.0",
"@ledgerhq/native-ui": "^0.7.16",
"@ledgerhq/react-native-hid": "^6.28.2",
Expand Down
127 changes: 127 additions & 0 deletions src/screens/AddAccounts/01-SelectCrypto.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// @flow
import React, { useMemo } from "react";
import { Trans } from "react-i18next";
import { StyleSheet, View, FlatList, SafeAreaView } from "react-native";
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/live-common/lib/types";
import {
isCurrencySupported,
listTokens,
listSupportedCurrencies,
useCurrenciesByMarketcapWithStatus,
} from "@ledgerhq/live-common/lib/currencies";

import { useTheme } from "@react-navigation/native";
import { ScreenName } from "../../const";
import { TrackScreen } from "../../analytics";
import FilteredSearchBar from "../../components/FilteredSearchBar";
import CurrencyRow from "../../components/CurrencyRow";
import LText from "../../components/LText";

const SEARCH_KEYS = ["name", "ticker"];

type Props = {
devMode: boolean;
navigation: any;
route: { params: { filterCurrencyIds?: string[] } };
};

const keyExtractor = currency => currency.id;

const renderEmptyList = () => (
<View>
<LText>
<Trans i18nKey="common.noCryptoFound" />
</LText>
</View>
);

const listSupportedTokens = () =>
listTokens().filter(t => isCurrencySupported(t.parentCurrency));

export default function AddAccountsSelectCrypto({ navigation, route }: Props) {
const { colors } = useTheme();
const { filterCurrencyIds = [] } = route.params || {};
const cryptoCurrencies = useMemo(
() =>
listSupportedCurrencies()
.concat(listSupportedTokens())
.filter(
({ id }) =>
filterCurrencyIds.length <= 0 || filterCurrencyIds.includes(id),
),
[filterCurrencyIds],
);

const { currencies } = useCurrenciesByMarketcapWithStatus(cryptoCurrencies);

const onPressCurrency = (currency: CryptoCurrency) => {
navigation.navigate(ScreenName.AddAccountsSelectDevice, {
...(route?.params ?? {}),
currency,
});
};

const onPressToken = (token: TokenCurrency) => {
navigation.navigate(ScreenName.AddAccountsTokenCurrencyDisclaimer, {
token,
});
};

const onPressItem = (currencyOrToken: CryptoCurrency | TokenCurrency) => {
if (currencyOrToken.type === "TokenCurrency") {
onPressToken(currencyOrToken);
} else {
onPressCurrency(currencyOrToken);
}
};

const renderList = items => (
<FlatList
contentContainerStyle={styles.list}
data={items}
renderItem={({ item }) => (
<CurrencyRow currency={item} onPress={onPressItem} />
)}
keyExtractor={keyExtractor}
showsVerticalScrollIndicator={false}
keyboardDismissMode="on-drag"
/>
);

return (
<SafeAreaView style={[styles.root, { backgroundColor: colors.background }]}>
<TrackScreen category="AddAccounts" name="SelectCrypto" />
<View style={styles.searchContainer}>
<FilteredSearchBar
keys={SEARCH_KEYS}
inputWrapperStyle={styles.filteredSearchInputWrapperStyle}
list={currencies || []}
renderList={renderList}
renderEmptySearch={renderEmptyList}
/>
</View>
</SafeAreaView>
);
}

const styles = StyleSheet.create({
root: {
flex: 1,
},
searchContainer: {
paddingTop: 16,
flex: 1,
},
list: {
paddingBottom: 32,
},
filteredSearchInputWrapperStyle: {
marginHorizontal: 16,
},
emptySearch: {
paddingHorizontal: 16,
},
emptySearchText: {
textAlign: "center",
},
});
14 changes: 9 additions & 5 deletions src/screens/Exchange/SelectCurrency.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type {
import {
isCurrencySupported,
listTokens,
useCurrenciesByMarketcap,
useCurrenciesByMarketcapWithStatus,
listSupportedCurrencies,
} from "@ledgerhq/live-common/lib/currencies";

Expand Down Expand Up @@ -64,11 +64,15 @@ export default function ExchangeSelectCrypto({ navigation, route }: Props) {
[],
);

const sortedCryptoCurrencies = useCurrenciesByMarketcap(cryptoCurrencies);
const {
currencies: sortedCryptoCurrencies,
} = useCurrenciesByMarketcapWithStatus(cryptoCurrencies);

const supportedCryptoCurrencies = sortedCryptoCurrencies.filter(currency =>
getSupportedCurrencies(mode).includes(currency.id),
);
const supportedCryptoCurrencies = sortedCryptoCurrencies
? sortedCryptoCurrencies.filter(currency =>
getSupportedCurrencies(mode).includes(currency.id),
)
: [];

const onPressCurrency = (currency: CryptoCurrency) => {
track("Buy Crypto Continue Button", { currencyName: currency.name });
Expand Down
8 changes: 5 additions & 3 deletions src/screens/RequestAccount/01-SelectCrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
AccountLike,
} from "@ledgerhq/live-common/lib/types";
import {
useCurrenciesByMarketcap,
useCurrenciesByMarketcapWithStatus,
findCryptoCurrencyById,
} from "@ledgerhq/live-common/lib/currencies";

Expand Down Expand Up @@ -55,7 +55,9 @@ export default function RequestAccountsSelectCrypto({
[currencies],
);

const sortedCryptoCurrencies = useCurrenciesByMarketcap(cryptoCurrencies);
const {
currencies: sortedCryptoCurrencies,
} = useCurrenciesByMarketcapWithStatus(cryptoCurrencies);

const onPressCurrency = (currency: CryptoCurrency) => {
navigation.navigate(ScreenName.RequestAccountsSelectAccount, {
Expand Down Expand Up @@ -85,7 +87,7 @@ export default function RequestAccountsSelectCrypto({
<FilteredSearchBar
keys={SEARCH_KEYS}
inputWrapperStyle={styles.filteredSearchInputWrapperStyle}
list={sortedCryptoCurrencies}
list={sortedCryptoCurrencies || []}
renderList={renderList}
renderEmptySearch={renderEmptyList}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/screens/Swap/FormSelection/SelectCurrencyScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Trans } from "react-i18next";
import { StyleSheet, View, FlatList, SafeAreaView } from "react-native";
import type { CryptoCurrency } from "@ledgerhq/live-common/lib/types";

import { useCurrenciesByMarketcap } from "@ledgerhq/live-common/lib/currencies";
import { useCurrenciesByMarketcapWithStatus } from "@ledgerhq/live-common/lib/currencies";
import { getSupportedCurrencies } from "@ledgerhq/live-common/lib/exchange/swap/logic";

import { useTheme } from "@react-navigation/native";
Expand Down Expand Up @@ -49,9 +49,9 @@ export default function SwapFormSelectCurrencyScreen({
c => c !== getAccountCurrency(swap.from.account),
)
: selectableCurrencies;
const sortedCryptoCurrencies = useCurrenciesByMarketcap(
maybeFilteredCurrencies,
);
const {
currencies: sortedCryptoCurrencies,
} = useCurrenciesByMarketcapWithStatus(maybeFilteredCurrencies);

const onPressCurrency = useCallback(
(currency: CryptoCurrency) => {
Expand Down
6 changes: 3 additions & 3 deletions src/screens/Swap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
getAccountUnit,
} from "@ledgerhq/live-common/lib/account";
import { useDispatch, useSelector } from "react-redux";
import { useCurrenciesByMarketcap } from "@ledgerhq/live-common/lib/currencies";
import { useCurrenciesByMarketcapWithStatus } from "@ledgerhq/live-common/lib/currencies";
import AccountAmountRow from "./FormSelection/AccountAmountRow";
import Button from "../../components/Button";
import LText from "../../components/LText";
Expand Down Expand Up @@ -107,10 +107,10 @@ function SwapForm({
? selectableCurrencies.filter(c => c !== getAccountCurrency(defaultAccount))
: selectableCurrencies;

const sortedCryptoCurrencies = useCurrenciesByMarketcap(
const { currencies } = useCurrenciesByMarketcapWithStatus(
maybeFilteredCurrencies,
);

const sortedCryptoCurrencies = useMemo(() => currencies || [], [currencies]);
const defaultCurrency = route?.params?.swap?.from.account
? sortedCryptoCurrencies.find(
c => c !== getAccountCurrency(route?.params?.swap?.from.account),
Expand Down
63 changes: 44 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,13 @@
dependencies:
regenerator-runtime "^0.13.4"

"@babel/runtime@^7.17.9":
version "7.17.9"
resolved "https://registry.yarnpkg.com/@babel/runtime/-/runtime-7.17.9.tgz#d19fbf802d01a8cb6cf053a64e472d42c434ba72"
integrity sha512-lSiBBvodq29uShpWGNbgFdKYNiFDo5/HIYsaCEY9ff4sb10x9jizo2+pRrSyF4jKZCXqgzuqBOQKbUm90gQwJg==
dependencies:
regenerator-runtime "^0.13.4"

"@babel/template@^7.0.0", "@babel/template@^7.16.0", "@babel/template@^7.16.7", "@babel/template@^7.3.3":
version "7.16.7"
resolved "https://registry.yarnpkg.com/@babel/template/-/template-7.16.7.tgz#8d126c8701fde4d66b264b3eba3d96f07666d155"
Expand Down Expand Up @@ -2556,6 +2563,16 @@
rxjs "6"
semver "^7.3.5"

"@ledgerhq/[email protected]", "@ledgerhq/devices@^6.27.1":
version "6.27.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-6.27.1.tgz#3b13ab1d1ba8201e9e74a08f390560483978c962"
integrity sha512-jX++oy89jtv7Dp2X6gwt3MMkoajel80JFWcdc0HCouwDsV1mVJ3SQdwl/bQU0zd8HI6KebvUP95QTwbQLLK/RQ==
dependencies:
"@ledgerhq/errors" "^6.10.0"
"@ledgerhq/logs" "^6.10.0"
rxjs "6"
semver "^7.3.5"

"@ledgerhq/devices@^5.11.0", "@ledgerhq/devices@^5.51.1":
version "5.51.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-5.51.1.tgz#d741a4a5d8f17c2f9d282fd27147e6fe1999edb7"
Expand Down Expand Up @@ -2729,6 +2746,15 @@
"@ledgerhq/errors" "^6.10.0"
events "^3.3.0"

"@ledgerhq/[email protected]", "@ledgerhq/hw-transport@^6.27.1":
version "6.27.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-6.27.1.tgz#88072278f69c279cb6569352acd4ae2fec33ace3"
integrity sha512-hnE4/Fq1YzQI4PA1W0H8tCkI99R3UWDb3pJeZd6/Xs4Qw/q1uiQO+vNLC6KIPPhK0IajUfuI/P2jk0qWcMsuAQ==
dependencies:
"@ledgerhq/devices" "^6.27.1"
"@ledgerhq/errors" "^6.10.0"
events "^3.3.0"

"@ledgerhq/hw-transport@^5.11.0", "@ledgerhq/hw-transport@^5.19.1", "@ledgerhq/hw-transport@^5.51.1":
version "5.51.1"
resolved "https://registry.yarnpkg.com/@ledgerhq/hw-transport/-/hw-transport-5.51.1.tgz#8dd14a8e58cbee4df0c29eaeef983a79f5f22578"
Expand Down Expand Up @@ -2770,10 +2796,9 @@
bignumber.js "^9.0.2"
json-rpc-2.0 "^1.0.0"

"@ledgerhq/live-common@22.1.0":
"@ledgerhq/live-common@https://github.com/LedgerHQ/ledger-live-common.git#7108d9c61fe7cea9e660f9e9aa29a97df9b65c94":
version "22.1.0"
resolved "https://registry.yarnpkg.com/@ledgerhq/live-common/-/live-common-22.1.0.tgz#0884a0dbfc541119267c2b873fb5e176f6474bad"
integrity sha512-gO8Ou5xriJ1FTDhO1/KgHnu6xacM4nDT0Z6nUcYSONCH6ElTjLA1jFR5qNxceV5/vhqBcIau5MKQw0W9J2zZcA==
resolved "https://github.com/LedgerHQ/ledger-live-common.git#7108d9c61fe7cea9e660f9e9aa29a97df9b65c94"
dependencies:
"@celo/contractkit" "^1.5.2"
"@celo/wallet-base" "^1.5.2"
Expand Down Expand Up @@ -3073,13 +3098,13 @@
"@octokit/openapi-types" "^11.2.0"

"@polkadot/keyring@^9.0.1":
version "9.1.1"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-9.1.1.tgz#d4bf244d6dd23d06fed9334e79c0d46a8fdb5988"
integrity sha512-qjnO1795v7wDvU2hW0H+z7bMPNV3xcVnIjozt3/+Y5Lphu3Tohh3WNgf9uNKIUTwbWxTF4wWsiUM1ajY4CRuMA==
version "9.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-9.2.1.tgz#fecb189478d8f7e12ca413971691b5c7a887713a"
integrity sha512-6TxcVX5ABtqYb7aJmWdeCLWx11i6MoDX5pKbGqlCuLRzSKWRjgVpBEsKOfDBClBFuMJfTOgkmuyeXdBrGIsH4w==
dependencies:
"@babel/runtime" "^7.17.9"
"@polkadot/util" "9.1.1"
"@polkadot/util-crypto" "9.1.1"
"@polkadot/util" "9.2.1"
"@polkadot/util-crypto" "9.2.1"

"@polkadot/[email protected]":
version "8.0.6-8"
Expand All @@ -3089,13 +3114,13 @@
"@babel/runtime" "^7.16.3"

"@polkadot/networks@^9.0.1":
version "9.1.1"
resolved "https://registry.yarnpkg.com/@polkadot/networks/-/networks-9.1.1.tgz#3b99dcedd1ed626f6efecc642e1dcebca64978e3"
integrity sha512-L/jk8vDr4shzGEVOqOimmXySLpbrN8+qlk+BR3A6rFa4N+XjtcGvnnt+so+rXwJOu7U4/ir6qPU2Iq63XbQTMA==
version "9.2.1"
resolved "https://registry.yarnpkg.com/@polkadot/networks/-/networks-9.2.1.tgz#9f844a00a9f249dc697d3f85c5847fe9b2003f0a"
integrity sha512-uewpJBJWdl5r78FQT9qTeABbUB6RWxk4BoMq27ZKt4B+0riiXJYBVOCnsYqK8vhUq19pgk8XBXuxltVQQ+wGgQ==
dependencies:
"@babel/runtime" "^7.17.9"
"@polkadot/util" "9.1.1"
"@substrate/ss58-registry" "^1.17.0"
"@polkadot/util" "9.2.1"
"@substrate/ss58-registry" "^1.18.0"

"@polkadot/[email protected]":
version "0.87.5"
Expand Down Expand Up @@ -3169,7 +3194,7 @@
"@babel/runtime" "^7.16.3"
color "^3.2.1"

"@polkadot/[email protected]", "@polkadot/util-crypto@9.1.1", "@polkadot/util-crypto@^8.1.2", "@polkadot/util-crypto@^9.0.1":
"@polkadot/[email protected]", "@polkadot/util-crypto@9.2.1", "@polkadot/util-crypto@^8.1.2", "@polkadot/util-crypto@^9.0.1":
version "8.0.6-8"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-8.0.6-8.tgz#47735fcf409819f3eaeaf9a7099ff170e501adda"
integrity sha512-ssITWN1mRwvzM0wexDaGAfHWWbqOys4D3vg8mY8WYUZ8NKbdGoOSirnOY/0LlsKDUSQ/kRCtWDiPHZs7UC3Y1A==
Expand All @@ -3187,7 +3212,7 @@
micro-base "^0.9.0"
tweetnacl "^1.0.3"

"@polkadot/[email protected]", "@polkadot/util@9.1.1", "@polkadot/util@^8.1.2", "@polkadot/util@^9.0.1":
"@polkadot/[email protected]", "@polkadot/util@9.2.1", "@polkadot/util@^8.1.2", "@polkadot/util@^9.0.1":
version "8.0.6-8"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-8.0.6-8.tgz#83e18960abc49d7dc523bd5375923064742d12bf"
integrity sha512-ZH3Yb7tFaatBjiurK8sDcK+jupmgSK5NEB0j89Jwyv/R+wwTjkyeUlRg0wo7srvRQGfazIQMyryD4pFVRaQx3g==
Expand Down Expand Up @@ -3994,10 +4019,10 @@
"@styled-system/core" "^5.1.2"
"@styled-system/css" "^5.1.5"

"@substrate/ss58-registry@^1.17.0":
version "1.17.0"
resolved "https://registry.yarnpkg.com/@substrate/ss58-registry/-/ss58-registry-1.17.0.tgz#a6a50dbef67da0114aff7cdae7c6eec685c5983b"
integrity sha512-YdQOxCtEZLnYZFg/zSzfROYtvIs5+iLD7p/VHoll7AVEhrPAmxgF5ggMDB2Dass7dfwABVx7heATbPFNg95Q8w==
"@substrate/ss58-registry@^1.18.0":
version "1.18.0"
resolved "https://registry.yarnpkg.com/@substrate/ss58-registry/-/ss58-registry-1.18.0.tgz#0744480e880ae8e557327557a2a7fc95577292ec"
integrity sha512-nAA1qsorxgdDnx5ie/FL90nM2riTNn72wIq8jtWsR8trsk1uTIHJgQQjEgviFCtMg4Ws9bEjo8DkWBgVGdPFmw==

"@szmarczak/http-timer@^1.1.2":
version "1.1.2"
Expand Down