Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Coin Modularization] Tezos #6754

Merged
merged 21 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/forty-chefs-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@ledgerhq/coin-tezos": minor
"@ledgerhq/coin-algorand": patch
"@ledgerhq/coin-polkadot": patch
"@ledgerhq/coin-near": patch
"@ledgerhq/coin-evm": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
"@ledgerhq/coin-framework": patch
---

Move Tezos in its own package
8 changes: 5 additions & 3 deletions apps/ledger-live-desktop/src/renderer/actions/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import { useSelector, useDispatch } from "react-redux";
import { createSelector } from "reselect";
// TODO make a generic way to implement this for each family
// eslint-disable-next-line no-restricted-imports
import { isAccountDelegating } from "@ledgerhq/live-common/families/tezos/bakers";
import { flattenSortAccounts } from "@ledgerhq/live-wallet/ordering";
import { isAccountDelegating } from "@ledgerhq/live-common/families/tezos/staking";
import {
flattenSortAccounts,
sortAccountsComparatorFromOrder,
} from "@ledgerhq/live-wallet/ordering";
import { reorderAccounts } from "~/renderer/actions/accounts";
import {
useCalculateCountervalueCallback as useCalculateCountervalueCallbackCommon,
Expand All @@ -24,7 +27,6 @@ import { useExtraSessionTrackingPair } from "./deprecated/ondemand-countervalues
import { useMarketPerformanceTrackingPairs } from "./marketperformance";
import { LiveConfig } from "@ledgerhq/live-config/LiveConfig";
import { walletSelector } from "../reducers/wallet";
import { sortAccountsComparatorFromOrder } from "@ledgerhq/live-wallet/ordering";
import { FlattenAccountsOptions } from "@ledgerhq/live-common/account/index";

// provide redux states via custom hook wrapper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isAccountEmpty } from "@ledgerhq/live-common/account/index";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/bakers";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/react";
import { useCallback } from "react";
import { useTranslation } from "react-i18next";
import { useDispatch } from "react-redux";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { useDispatch, useSelector } from "react-redux";
import { Trans, useTranslation } from "react-i18next";
import invariant from "invariant";
import { Account, AccountLike, Operation, SubAccount } from "@ledgerhq/types-live";
import { useBakers } from "@ledgerhq/live-common/families/tezos/bakers";
import whitelist from "@ledgerhq/live-common/families/tezos/bakers.whitelist-default";
import { useBakers } from "@ledgerhq/live-common/families/tezos/react";
import { whitelist } from "@ledgerhq/live-common/families/tezos/staking";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { getMainAccount, addPendingOperation } from "@ledgerhq/live-common/account/index";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { OperationDetails } from "~/renderer/drawers/OperationDetails";
import { setDrawer } from "~/renderer/drawers/Provider";
import { StepProps } from "../types";
import { useEffect } from "react";
import { useBaker } from "@ledgerhq/live-common/families/tezos/bakers";
import { useBaker } from "@ledgerhq/live-common/families/tezos/react";
import { useLocalizedUrl } from "~/renderer/hooks/useLocalizedUrls";
import { urls } from "~/config/urls";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import invariant from "invariant";
import React from "react";
import styled from "styled-components";
import { getAccountCurrency } from "@ledgerhq/live-common/account/index";
import { useBaker, useDelegation } from "@ledgerhq/live-common/families/tezos/bakers";
import { useBaker, useDelegation } from "@ledgerhq/live-common/families/tezos/react";
import { Baker } from "@ledgerhq/live-common/families/tezos/types";
import { Trans } from "react-i18next";
import TrackPage from "~/renderer/analytics/TrackPage";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import invariant from "invariant";
import styled from "styled-components";
import { Trans } from "react-i18next";
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import { useBakers } from "@ledgerhq/live-common/families/tezos/bakers";
import { useBakers } from "@ledgerhq/live-common/families/tezos/react";
import { Baker } from "@ledgerhq/live-common/families/tezos/types";
import bakersWhitelistDefault from "@ledgerhq/live-common/families/tezos/bakers.whitelist-default";
import { whitelist as bakersWhitelistDefault } from "@ledgerhq/live-common/families/tezos/staking";
import { openURL } from "~/renderer/linking";
import TrackPage from "~/renderer/analytics/TrackPage";
import Box from "~/renderer/components/Box";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import styled, { useTheme } from "styled-components";
import { Trans } from "react-i18next";
import { useDispatch } from "react-redux";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/bakers";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/react";
import { openModal } from "~/renderer/actions/modals";
import Box from "~/renderer/components/Box";
import Text from "~/renderer/components/Text";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import styled from "styled-components";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/bakers";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/react";
import { SubAccount } from "@ledgerhq/types-live";
import { openURL } from "~/renderer/linking";
import { openModal } from "~/renderer/actions/modals";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getMainAccount, shortAddressPreview } from "@ledgerhq/live-common/account/index";
import { getAddressExplorer, getDefaultExplorerView } from "@ledgerhq/live-common/explorers";
import { useBaker } from "@ledgerhq/live-common/families/tezos/bakers";
import { useBaker } from "@ledgerhq/live-common/families/tezos/react";
import invariant from "invariant";
import React, { useCallback } from "react";
import Text from "~/renderer/components/Text";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useCallback } from "react";
import { useDispatch } from "react-redux";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/bakers";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/react";
import { SubAccount } from "@ledgerhq/types-live";
import { openModal } from "~/renderer/actions/modals";
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { differenceInCalendarDays } from "date-fns";
import { StyleSheet, Platform, View } from "react-native";
import { AccountLike, Account } from "@ledgerhq/types-live";
import { shortAddressPreview, getAccountCurrency } from "@ledgerhq/live-common/account/index";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/bakers";
import { useDelegation } from "@ledgerhq/live-common/families/tezos/react";
import { Flex, Text } from "@ledgerhq/native-ui";
import LText from "~/components/LText";
import CurrencyUnitValue from "~/components/CurrencyUnitValue";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useNavigation, ParamListBase, RouteProp } from "@react-navigation/nativ
import { AccountLike, Account } from "@ledgerhq/types-live";
import { getMainAccount } from "@ledgerhq/live-common/account/index";
import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index";
import { isAccountDelegating } from "@ledgerhq/live-common/families/tezos/bakers";
import { isAccountDelegating } from "@ledgerhq/live-common/families/tezos/staking";
import { Text } from "@ledgerhq/native-ui";
import { NavigatorName, ScreenName } from "~/const";
import IlluStaking from "./IlluStaking";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransact
import { getAccountBridge } from "@ledgerhq/live-common/bridge/index";
import type { Transaction as TezosTransaction } from "@ledgerhq/live-common/families/tezos/types";
import type { Baker } from "@ledgerhq/live-common/families/tezos/types";
import { useBakers } from "@ledgerhq/live-common/families/tezos/bakers";
import whitelist from "@ledgerhq/live-common/families/tezos/bakers.whitelist-default";
import { useBakers } from "@ledgerhq/live-common/families/tezos/react";
import { whitelist } from "@ledgerhq/live-common/families/tezos/staking";
import { useTheme } from "@react-navigation/native";
import { accountScreenSelector } from "~/reducers/accounts";
import { TrackScreen } from "~/analytics";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { getAccountCurrency, shortAddressPreview } from "@ledgerhq/live-common/a
import { getCurrencyColor } from "@ledgerhq/live-common/currencies/index";
import type { Transaction as TezosTransaction } from "@ledgerhq/live-common/families/tezos/types";
import useBridgeTransaction from "@ledgerhq/live-common/bridge/useBridgeTransaction";
import { useDelegation, useBaker, useBakers } from "@ledgerhq/live-common/families/tezos/bakers";
import whitelist from "@ledgerhq/live-common/families/tezos/bakers.whitelist-default";
import { useDelegation, useBaker, useBakers } from "@ledgerhq/live-common/families/tezos/react";
import { whitelist } from "@ledgerhq/live-common/families/tezos/staking";
import type { AccountLike } from "@ledgerhq/types-live";
import { useTheme } from "@react-navigation/native";
import { Alert } from "@ledgerhq/native-ui";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { View, StyleSheet } from "react-native";
import { useSelector } from "react-redux";
import { Trans } from "react-i18next";
import { useTheme } from "@react-navigation/native";
import { useBaker } from "@ledgerhq/live-common/families/tezos/bakers";
import { useBaker } from "@ledgerhq/live-common/families/tezos/react";
import { accountScreenSelector } from "~/reducers/accounts";
import { TrackScreen, track } from "~/analytics";
import { ScreenName } from "~/const";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useCallback } from "react";
import { Linking, StyleSheet } from "react-native";
import type { AccountLike, Account } from "@ledgerhq/types-live";
import type { Transaction } from "@ledgerhq/live-common/generated/types";
import { useBaker } from "@ledgerhq/live-common/families/tezos/bakers";
import { useBaker } from "@ledgerhq/live-common/families/tezos/react";
import { shortAddressPreview, getMainAccount } from "@ledgerhq/live-common/account/index";
import { getDefaultExplorerView, getAddressExplorer } from "@ledgerhq/live-common/explorers";
import { toLocaleString } from "@ledgerhq/live-common/currencies/index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Account, AccountLike } from "@ledgerhq/types-live";
import {
getAccountDelegationSync,
isAccountDelegating,
} from "@ledgerhq/live-common/families/tezos/bakers";
} from "@ledgerhq/live-common/families/tezos/staking";
import { ParamListBase, RouteProp } from "@react-navigation/native";
import { IconsLegacy } from "@ledgerhq/native-ui";
import { NavigatorName, ScreenName } from "~/const";
Expand Down
38 changes: 36 additions & 2 deletions libs/coin-framework/src/account/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import BigNumber from "bignumber.js";
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
import type { Account, TokenAccount } from "@ledgerhq/types-live";
import type { Account, Operation, TokenAccount } from "@ledgerhq/types-live";
import { getTokenById } from "@ledgerhq/cryptoassets/tokens";
import {
emptyHistoryCache,
getAccountCurrency,
getAccountSpendableBalance,
getFeesCurrency,
} from ".";
import { isAccountEmpty, clearAccount } from "./helpers";
import { isAccountEmpty, clearAccount, areAllOperationsLoaded } from "./helpers";

const mockAccount = {} as Account;
const tokenAccount = {
Expand Down Expand Up @@ -219,3 +219,37 @@ describe(clearAccount.name, () => {
});
});
});

describe(areAllOperationsLoaded.name, () => {
describe("given an account with subAccounts", () => {
beforeEach(() => {
mockAccount.type = "Account";
mockAccount.operations = [];
mockAccount.operationsCount = 0;
mockAccount.subAccounts = [
{
operations: [],
operationsCount: 0,
},
{
operations: [{} as Operation],
operationsCount: 1,
},
] as TokenAccount[];
});
describe("when sub account operation aren't loaded", () => {
beforeEach(() => {
(mockAccount.subAccounts as TokenAccount[])[1].operations = [];
});
it("should return false", () => {
expect(areAllOperationsLoaded(mockAccount)).toEqual(false);
});
});

describe("when sub account operation are loaded", () => {
it("should return true", () => {
expect(areAllOperationsLoaded(mockAccount)).toEqual(true);
});
});
});
});
12 changes: 12 additions & 0 deletions libs/coin-framework/src/account/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,15 @@ export function getParentAccount(account: AccountLike, accounts: AccountLike[]):
}
}
}

export function areAllOperationsLoaded(account: AccountLike): boolean {
if (account.operationsCount !== account.operations.length) {
return false;
}

if (account.type === "Account" && account.subAccounts) {
return account.subAccounts.every(areAllOperationsLoaded);
}

return true;
}
1 change: 1 addition & 0 deletions libs/coin-framework/src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {
isAccount,
isTokenAccount,
getParentAccount,
areAllOperationsLoaded,
} from "./helpers";
export { addPendingOperation } from "./pending";
export { getReceiveFlowError, checkAccountSupported } from "./support";
18 changes: 13 additions & 5 deletions libs/coin-framework/src/bridge/jsHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ describe("jsHelpers", () => {
describe("makeSync", () => {
it("returns a function to update account that give a new instance of account", async () => {
// Given
const account = createAccount("12");
const account = createAccount({
id: "12",
creationDate: new Date("2024-05-12T17:04:12"),
lastSyncDate: new Date("2024-05-12T17:04:12"),
});

// When
const accountUpdater = makeSync({
Expand All @@ -68,7 +72,11 @@ describe("jsHelpers", () => {

it("returns a account with a corrected formatted id", async () => {
// Given
const account = createAccount("12");
const account = createAccount({
id: "12",
creationDate: new Date("2024-05-12T17:04:12"),
lastSyncDate: new Date("2024-05-12T17:04:12"),
});

// When
const accountUpdater = makeSync({
Expand Down Expand Up @@ -105,12 +113,12 @@ const emptyHistoryCache = {

// Call once for all tests the currencies. Relies on real implementation to check also consistency.
const bitcoinCurrency = listCryptoCurrencies(true).find(c => c.id === "bitcoin")!;
function createAccount(id: string): Account {
function createAccount(init: Partial<Account>): Account {
const currency = bitcoinCurrency;

return {
type: "Account",
id,
id: init.id ?? "12",
seedIdentifier: "",
derivationMode: "",
index: 0,
Expand All @@ -119,7 +127,7 @@ function createAccount(id: string): Account {
used: true,
balance: new BigNumber(0),
spendableBalance: new BigNumber(0),
creationDate: new Date(),
creationDate: init.creationDate ?? new Date(),
blockHeight: 0,
currency,
operationsCount: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import BigNumber from "bignumber.js";
import { u8aConcat } from "@polkadot/util";
import type { SignOperationEvent } from "@ledgerhq/types-live";
import type { PolkadotOperationMode, PolkadotSigner, PolkadotOperationExtra } from "../types";
import { createFixtureAccount, createFixtureTransaction } from "../types/bridge.fixture";
import buildSignOperation from "./signOperation";
import { SignOperationEvent } from "@ledgerhq/types-live";
import { createRegistryAndExtrinsics } from "../network/common";
import {
fixtureChainSpec,
Expand Down
11 changes: 0 additions & 11 deletions libs/coin-modules/coin-solana/src/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@ export type SolanaAddress = {
export type SolanaSignature = {
signature: Buffer;
};
// enum PubKeyDisplayMode {
// LONG,
// SHORT,
// }
// type AppConfig = {
// blindSigningEnabled: boolean;
// pubKeyDisplayMode: PubKeyDisplayMode;
// version: string;
// };
export interface SolanaSigner {
getAddress(path: string, display?: boolean): Promise<SolanaAddress>;
signTransaction(path: string, txBuffer: Buffer): Promise<SolanaSignature>;
// signOffchainMessage(path: string, msgBuffer: Buffer): Promise<SolanaSignature>;
// getAppConfiguration(): Promise<AppConfig>;
}
20 changes: 20 additions & 0 deletions libs/coin-modules/coin-tezos/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module.exports = {
env: {
browser: true,
es6: true,
},
overrides: [
{
files: ["src/**/*.test.{ts,tsx}"],
env: {
"jest/globals": true,
},
plugins: ["jest"],
},
],
rules: {
"no-console": ["error", { allow: ["warn", "error"] }],
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-explicit-any": "warn",
},
};