From a609ce0c7d9c9d100988e00e4f4f80c690e33dc5 Mon Sep 17 00:00:00 2001 From: Maria Ayelen Murano Date: Fri, 11 Oct 2024 16:55:11 -0300 Subject: [PATCH] feat: upgrade kadena, add sender and receiver chain id inputs in mobile --- .../src/renderer/families/kadena/index.ts | 4 +- .../RootNavigator/types/SendFundsNavigator.ts | 55 +++++--- .../types/SignTransactionNavigator.ts | 55 ++++++-- .../RootNavigator/types/SwapNavigator.ts | 73 +++++++--- .../src/const/navigation.ts | 3 +- .../src/families/kadena/AccountSubHeader.tsx | 2 +- .../kadena/ScreenEditReceiverChainId.tsx | 127 ++++++++++++++++++ ...hainID.tsx => ScreenEditSenderChainId.tsx} | 99 +++++++------- .../src/families/kadena/SendRowChainId.tsx | 116 ++++++++++++++++ .../src/families/kadena/SendRowsCustom.tsx | 25 ++++ .../src/families/kadena/index.ts | 5 +- .../src/families/kadena/operationDetails.tsx | 28 ++++ .../src/locales/en/common.json | 5 +- .../coin-kadena/src/api/network.ts | 6 +- .../coin-modules/coin-kadena/src/bridge/js.ts | 4 +- libs/ledger-live-common/package.json | 2 +- 16 files changed, 494 insertions(+), 115 deletions(-) create mode 100644 apps/ledger-live-mobile/src/families/kadena/ScreenEditReceiverChainId.tsx rename apps/ledger-live-mobile/src/families/kadena/{ScreenEditChainID.tsx => ScreenEditSenderChainId.tsx} (61%) create mode 100644 apps/ledger-live-mobile/src/families/kadena/SendRowChainId.tsx create mode 100644 apps/ledger-live-mobile/src/families/kadena/SendRowsCustom.tsx create mode 100644 apps/ledger-live-mobile/src/families/kadena/operationDetails.tsx diff --git a/apps/ledger-live-desktop/src/renderer/families/kadena/index.ts b/apps/ledger-live-desktop/src/renderer/families/kadena/index.ts index 310de5be5e95..a818bbc3c42b 100644 --- a/apps/ledger-live-desktop/src/renderer/families/kadena/index.ts +++ b/apps/ledger-live-desktop/src/renderer/families/kadena/index.ts @@ -3,14 +3,16 @@ import { Transaction, TransactionStatus, } from "@ledgerhq/live-common/families/kadena/types"; +import { Account } from "@ledgerhq/types-live"; import { LLDCoinFamily } from "../types"; import AccountSubHeader from "./AccountSubHeader"; +import operationDetails from "./operationDetails"; import sendRecipientFields from "./SendRecipientFields"; -import { Account } from "@ledgerhq/types-live"; const family: LLDCoinFamily = { AccountSubHeader, sendRecipientFields, + operationDetails, }; export default family; diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/SendFundsNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/SendFundsNavigator.ts index fafe2c858fe2..5d2c0840bfd3 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/SendFundsNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/SendFundsNavigator.ts @@ -1,22 +1,19 @@ -import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets"; -import { Account, AccountLike, ProtoNFT } from "@ledgerhq/types-live"; -import type { Device } from "@ledgerhq/live-common/hw/actions/types"; -import type { Operation } from "@ledgerhq/types-live"; -import type { Transaction, TransactionStatus } from "@ledgerhq/live-common/generated/types"; import type { Transaction as EvmTransaction, GasOptions } from "@ledgerhq/coin-evm/types/index"; +import { Result } from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import type { - CardanoAccount, - Transaction as CardanoTransaction, -} from "@ledgerhq/live-common/families/cardano/types"; + AlgorandAccount, + AlgorandTransaction, + TransactionStatus as AlgorandTransactionStatus, +} from "@ledgerhq/live-common/families/algorand/types"; import type { Transaction as BitcoinTransaction, TransactionStatus as BitcoinTransactionStatus, } from "@ledgerhq/live-common/families/bitcoin/types"; import type { - AlgorandAccount, - AlgorandTransaction, - TransactionStatus as AlgorandTransactionStatus, -} from "@ledgerhq/live-common/families/algorand/types"; + CardanoAccount, + Transaction as CardanoTransaction, +} from "@ledgerhq/live-common/families/cardano/types"; +import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/families/casper/types"; import { CosmosAccount, Transaction as CosmosTransaction, @@ -26,22 +23,22 @@ import { Transaction as CryptoOrgTransaction, } from "@ledgerhq/live-common/families/crypto_org/types"; import { Transaction as HederaTransaction } from "@ledgerhq/live-common/families/hedera/types"; +import type { Transaction as ICPTransaction } from "@ledgerhq/live-common/families/internet_computer/types"; +import { Transaction as KadenaTransaction } from "@ledgerhq/live-common/families/kadena/types"; import { SolanaAccount, Transaction as SolanaTransaction, } from "@ledgerhq/live-common/families/solana/types"; -import { - KadenaAccount, - Transaction as KadenaTransaction, -} from "@ledgerhq/live-common/families/kadena/types"; -import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/families/xrp/types"; -import type { Transaction as ICPTransaction } from "@ledgerhq/live-common/families/internet_computer/types"; -import type { Transaction as StellarTransaction } from "@ledgerhq/live-common/families/stellar/types"; import type { Transaction as StacksTransaction } from "@ledgerhq/live-common/families/stacks/types"; -import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/families/casper/types"; +import type { Transaction as StellarTransaction } from "@ledgerhq/live-common/families/stellar/types"; import type { Transaction as TonTransaction } from "@ledgerhq/live-common/families/ton/types"; +import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/families/xrp/types"; +import type { Transaction, TransactionStatus } from "@ledgerhq/live-common/generated/types"; +import type { Device } from "@ledgerhq/live-common/hw/actions/types"; +import type { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets"; +import type { Operation } from "@ledgerhq/types-live"; +import { Account, AccountLike, ProtoNFT } from "@ledgerhq/types-live"; import BigNumber from "bignumber.js"; -import { Result } from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { ScreenName } from "~/const"; export type SendFundsNavigatorStackParamList = { @@ -363,7 +360,21 @@ export type SendFundsNavigatorStackParamList = { | ScreenName.SendSelectDevice | ScreenName.SwapForm; }; - [ScreenName.KadenaEditChainID]: { + [ScreenName.KadenaEditReceiverChainId]: { + accountId: string; + account: Account; + parentId?: string; + transaction: KadenaTransaction; + currentNavigation: + | ScreenName.SignTransactionSummary + | ScreenName.SendSummary + | ScreenName.SwapForm; + nextNavigation: + | ScreenName.SignTransactionSelectDevice + | ScreenName.SendSelectDevice + | ScreenName.SwapForm; + }; + [ScreenName.KadenaEditSenderChainId]: { accountId: string; account: Account; parentId?: string; diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/SignTransactionNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/SignTransactionNavigator.ts index 21e1eee1b1e2..f485f25af13c 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/SignTransactionNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/SignTransactionNavigator.ts @@ -1,18 +1,18 @@ -import { Transaction, TransactionStatus } from "@ledgerhq/live-common/generated/types"; import type { Transaction as EvmTransaction, GasOptions } from "@ledgerhq/coin-evm/types/index"; import type { - CardanoAccount, - Transaction as CardanoTransaction, -} from "@ledgerhq/live-common/families/cardano/types"; + AlgorandAccount, + AlgorandTransaction, + TransactionStatus as AlgorandTransactionStatus, +} from "@ledgerhq/live-common/families/algorand/types"; import type { Transaction as BitcoinTransaction, TransactionStatus as BitcoinTransactionStatus, } from "@ledgerhq/live-common/families/bitcoin/types"; import type { - AlgorandAccount, - AlgorandTransaction, - TransactionStatus as AlgorandTransactionStatus, -} from "@ledgerhq/live-common/families/algorand/types"; + CardanoAccount, + Transaction as CardanoTransaction, +} from "@ledgerhq/live-common/families/cardano/types"; +import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/families/casper/types"; import { CosmosAccount, Transaction as CosmosTransaction, @@ -21,17 +21,18 @@ import { CryptoOrgAccount, Transaction as CryptoOrgTransaction, } from "@ledgerhq/live-common/families/crypto_org/types"; +import { Transaction as HederaTransaction } from "@ledgerhq/live-common/families/hedera/types"; +import type { Transaction as ICPTransaction } from "@ledgerhq/live-common/families/internet_computer/types"; +import { Transaction as KadenaTransaction } from "@ledgerhq/live-common/families/kadena/types"; import { SolanaAccount, Transaction as SolanaTransaction, } from "@ledgerhq/live-common/families/solana/types"; -import { Transaction as HederaTransaction } from "@ledgerhq/live-common/families/hedera/types"; -import type { Transaction as ICPTransaction } from "@ledgerhq/live-common/families/internet_computer/types"; -import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/families/xrp/types"; -import type { Transaction as StellarTransaction } from "@ledgerhq/live-common/families/stellar/types"; import type { Transaction as StacksTransaction } from "@ledgerhq/live-common/families/stacks/types"; -import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/families/casper/types"; +import type { Transaction as StellarTransaction } from "@ledgerhq/live-common/families/stellar/types"; import type { Transaction as TonTransaction } from "@ledgerhq/live-common/families/ton/types"; +import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/families/xrp/types"; +import { Transaction, TransactionStatus } from "@ledgerhq/live-common/generated/types"; import { Device } from "@ledgerhq/live-common/hw/actions/types"; import { Account, Operation, SignedOperation } from "@ledgerhq/types-live"; import BigNumber from "bignumber.js"; @@ -327,4 +328,32 @@ export type SignTransactionNavigatorParamList = { | ScreenName.SendSelectDevice | ScreenName.SwapForm; }; + [ScreenName.KadenaEditReceiverChainId]: { + accountId: string; + account: Account; + parentId?: string; + transaction: KadenaTransaction; + currentNavigation: + | ScreenName.SignTransactionSummary + | ScreenName.SendSummary + | ScreenName.SwapForm; + nextNavigation: + | ScreenName.SignTransactionSelectDevice + | ScreenName.SendSelectDevice + | ScreenName.SwapForm; + }; + [ScreenName.KadenaEditSenderChainId]: { + accountId: string; + account: Account; + parentId?: string; + transaction: KadenaTransaction; + currentNavigation: + | ScreenName.SignTransactionSummary + | ScreenName.SendSummary + | ScreenName.SwapForm; + nextNavigation: + | ScreenName.SignTransactionSelectDevice + | ScreenName.SendSelectDevice + | ScreenName.SwapForm; + }; }; diff --git a/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts index fabdb2249ade..63a994a56c50 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts @@ -1,28 +1,22 @@ +import type { Transaction as EvmTransaction, GasOptions } from "@ledgerhq/coin-evm/types/index"; import { ExchangeRate, SwapDataType } from "@ledgerhq/live-common/exchange/swap/types"; -import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets"; import { Transaction } from "@ledgerhq/live-common/generated/types"; -import type { Transaction as EvmTransaction, GasOptions } from "@ledgerhq/coin-evm/types/index"; +import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets"; import type { - DetailsSwapParamList, - DefaultAccountSwapParamList, - SwapSelectCurrency, - SwapPendingOperation, - SwapOperation, -} from "../../../screens/Swap/types"; -import type { - CardanoAccount, - Transaction as CardanoTransaction, -} from "@ledgerhq/live-common/families/cardano/types"; + AlgorandAccount, + AlgorandTransaction, + TransactionStatus as AlgorandTransactionStatus, +} from "@ledgerhq/live-common/families/algorand/types"; import type { Transaction as BitcoinTransaction, TransactionStatus as BitcoinTransactionStatus, } from "@ledgerhq/live-common/families/bitcoin/types"; import type { - AlgorandAccount, - AlgorandTransaction, - TransactionStatus as AlgorandTransactionStatus, -} from "@ledgerhq/live-common/families/algorand/types"; + CardanoAccount, + Transaction as CardanoTransaction, +} from "@ledgerhq/live-common/families/cardano/types"; +import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/families/casper/types"; import { CosmosAccount, Transaction as CosmosTransaction, @@ -31,20 +25,27 @@ import { CryptoOrgAccount, Transaction as CryptoOrgTransaction, } from "@ledgerhq/live-common/families/crypto_org/types"; +import { Transaction as HederaTransaction } from "@ledgerhq/live-common/families/hedera/types"; +import type { Transaction as ICPTransaction } from "@ledgerhq/live-common/families/internet_computer/types"; +import { Transaction as KadenaTransaction } from "@ledgerhq/live-common/families/kadena/types"; import { SolanaAccount, Transaction as SolanaTransaction, } from "@ledgerhq/live-common/families/solana/types"; -import { Transaction as HederaTransaction } from "@ledgerhq/live-common/families/hedera/types"; -import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/families/xrp/types"; -import type { Transaction as ICPTransaction } from "@ledgerhq/live-common/families/internet_computer/types"; -import type { Transaction as StellarTransaction } from "@ledgerhq/live-common/families/stellar/types"; import type { Transaction as StacksTransaction } from "@ledgerhq/live-common/families/stacks/types"; -import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/families/casper/types"; +import type { Transaction as StellarTransaction } from "@ledgerhq/live-common/families/stellar/types"; import type { Transaction as TonTransaction } from "@ledgerhq/live-common/families/ton/types"; -import BigNumber from "bignumber.js"; +import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/families/xrp/types"; import { Account, Operation } from "@ledgerhq/types-live"; +import BigNumber from "bignumber.js"; import { ScreenName } from "~/const"; +import type { + DefaultAccountSwapParamList, + DetailsSwapParamList, + SwapOperation, + SwapPendingOperation, + SwapSelectCurrency, +} from "../../../screens/Swap/types"; type Target = "from" | "to"; @@ -329,4 +330,32 @@ export type SwapNavigatorParamList = { | ScreenName.SendSelectDevice | ScreenName.SwapForm; }; + [ScreenName.KadenaEditReceiverChainId]: { + accountId: string; + account: Account; + parentId?: string; + transaction: KadenaTransaction; + currentNavigation: + | ScreenName.SignTransactionSummary + | ScreenName.SendSummary + | ScreenName.SwapForm; + nextNavigation: + | ScreenName.SignTransactionSelectDevice + | ScreenName.SendSelectDevice + | ScreenName.SwapForm; + }; + [ScreenName.KadenaEditSenderChainId]: { + accountId: string; + account: Account; + parentId?: string; + transaction: KadenaTransaction; + currentNavigation: + | ScreenName.SignTransactionSummary + | ScreenName.SendSummary + | ScreenName.SwapForm; + nextNavigation: + | ScreenName.SignTransactionSelectDevice + | ScreenName.SendSelectDevice + | ScreenName.SwapForm; + }; }; diff --git a/apps/ledger-live-mobile/src/const/navigation.ts b/apps/ledger-live-mobile/src/const/navigation.ts index 8c31781cd16b..bb5cf9c96545 100644 --- a/apps/ledger-live-mobile/src/const/navigation.ts +++ b/apps/ledger-live-mobile/src/const/navigation.ts @@ -530,7 +530,8 @@ export enum ScreenName { Web3HubApp = "Web3HubApp", // Kadena - KadenaEditChainID = "KadenaEditChainID", + KadenaEditSenderChainId = "KadenaEditSenderChainId", + KadenaEditReceiverChainId = "KadenaEditReceiverChainId", } export enum NavigatorName { diff --git a/apps/ledger-live-mobile/src/families/kadena/AccountSubHeader.tsx b/apps/ledger-live-mobile/src/families/kadena/AccountSubHeader.tsx index 57f2277dea88..2cbe2dd663f9 100644 --- a/apps/ledger-live-mobile/src/families/kadena/AccountSubHeader.tsx +++ b/apps/ledger-live-mobile/src/families/kadena/AccountSubHeader.tsx @@ -3,4 +3,4 @@ import AccountSubHeader from "~/components/AccountSubHeader"; export default function KadenaAccountSubHeader() { return ; -} \ No newline at end of file +} diff --git a/apps/ledger-live-mobile/src/families/kadena/ScreenEditReceiverChainId.tsx b/apps/ledger-live-mobile/src/families/kadena/ScreenEditReceiverChainId.tsx new file mode 100644 index 000000000000..264fa462926c --- /dev/null +++ b/apps/ledger-live-mobile/src/families/kadena/ScreenEditReceiverChainId.tsx @@ -0,0 +1,127 @@ +import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; +import { useIsFocused, useTheme } from "@react-navigation/native"; +import i18next from "i18next"; +import invariant from "invariant"; +import React, { useCallback, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { StyleSheet, View } from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { useSelector } from "react-redux"; +import Button from "~/components/Button"; +import TextInput from "~/components/FocusedTextInput"; +import KeyboardView from "~/components/KeyboardView"; +import { BaseComposite, StackNavigatorProps } from "~/components/RootNavigator/types/helpers"; +import { SendFundsNavigatorStackParamList } from "~/components/RootNavigator/types/SendFundsNavigator"; +import { SignTransactionNavigatorParamList } from "~/components/RootNavigator/types/SignTransactionNavigator"; +import { SwapNavigatorParamList } from "~/components/RootNavigator/types/SwapNavigator"; +import { ScreenName } from "~/const"; +import { accountScreenSelector } from "~/reducers/accounts"; + +type NavigationProps = BaseComposite< + StackNavigatorProps< + SendFundsNavigatorStackParamList | SignTransactionNavigatorParamList | SwapNavigatorParamList, + ScreenName.KadenaEditReceiverChainId + > +>; + +function KadenaEditReceiverChainId({ navigation, route }: NavigationProps) { + const isFocused = useIsFocused(); + const { colors } = useTheme(); + const { t } = useTranslation(); + const { account } = useSelector(accountScreenSelector(route)); + invariant(account, "account is required"); + + const [receiverChainId, setReceiverChainId] = useState( + route.params?.transaction.receiverChainId ?? 0, + ); + const onValidateReceiverChainID = useCallback((value: string) => { + const parsedValue = parseInt(value); + if (!isNaN(parsedValue) || value === "") { + setReceiverChainId(value !== "" ? parsedValue : null); + } + }, []); + + const onValidateChainID = useCallback(() => { + const bridge = getAccountBridge(account); + const { transaction } = route.params; + // @ts-expect-error FIXME: No current / next navigation params? + navigation.navigate(ScreenName.SendSummary, { + accountId: account.id, + transaction: bridge.updateTransaction(transaction, { + receiverChainId, + }), + }); + }, [navigation, route.params, account, receiverChainId]); + + return ( + + + {isFocused && ( + + )} + +