diff --git a/.changeset/eleven-hotels-share.md b/.changeset/eleven-hotels-share.md new file mode 100644 index 000000000000..ae8faa7e0449 --- /dev/null +++ b/.changeset/eleven-hotels-share.md @@ -0,0 +1,15 @@ +--- +"@ledgerhq/types-cryptoassets": patch +"@ledgerhq/cryptoassets": patch +"@ledgerhq/types-live": patch +"@ledgerhq/crypto-icons-ui": patch +"@actions/turbo-affected": patch +"@ledgerhq/coin-ton": patch +"ledger-live-desktop": patch +"live-mobile": patch +"@ledgerhq/live-common": patch +"@ledgerhq/coin-framework": patch +"@ledgerhq/live-cli": patch +--- + +add support for ton \ No newline at end of file diff --git a/.changeset/mean-trees-invite.md b/.changeset/mean-trees-invite.md new file mode 100644 index 000000000000..9b900af14266 --- /dev/null +++ b/.changeset/mean-trees-invite.md @@ -0,0 +1,15 @@ +--- +"@ledgerhq/types-cryptoassets": minor +"@ledgerhq/cryptoassets": minor +"@ledgerhq/types-live": minor +"@ledgerhq/crypto-icons-ui": minor +"ledger-live-desktop": minor +"live-mobile": minor +"@ledgerhq/live-common": minor +"@ledgerhq/coin-framework": minor +"@ledgerhq/live-config": minor +"@ledgerhq/live-cli": minor +"@ledgerhq/live-env": minor +--- + +Support for TON blockchain diff --git a/apps/cli/src/live-common-setup-base.ts b/apps/cli/src/live-common-setup-base.ts index 61ab6b5d54c4..ff2370140a86 100644 --- a/apps/cli/src/live-common-setup-base.ts +++ b/apps/cli/src/live-common-setup-base.ts @@ -93,6 +93,7 @@ setSupportedCurrencies([ "lukso", "filecoin", "linea", + "ton", "linea_sepolia", "blast", "blast_sepolia", diff --git a/apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts b/apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts index 8777771a8878..418f4e80f3d1 100644 --- a/apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts +++ b/apps/ledger-live-desktop/src/live-common-set-supported-currencies.ts @@ -92,4 +92,5 @@ setSupportedCurrencies([ "blast_sepolia", "scroll", "scroll_sepolia", + "ton", ]); diff --git a/apps/ledger-live-desktop/src/renderer/families/ton/AccountSubHeader.tsx b/apps/ledger-live-desktop/src/renderer/families/ton/AccountSubHeader.tsx new file mode 100644 index 000000000000..023ecd14bb59 --- /dev/null +++ b/apps/ledger-live-desktop/src/renderer/families/ton/AccountSubHeader.tsx @@ -0,0 +1,6 @@ +import React from "react"; +import AccountSubHeader from "../../components/AccountSubHeader/index"; + +export default function TonAccountSubHeader() { + return ; +} diff --git a/apps/ledger-live-desktop/src/renderer/families/ton/CommentField.tsx b/apps/ledger-live-desktop/src/renderer/families/ton/CommentField.tsx new file mode 100644 index 000000000000..cfe658d4d54b --- /dev/null +++ b/apps/ledger-live-desktop/src/renderer/families/ton/CommentField.tsx @@ -0,0 +1,51 @@ +import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; +import { Transaction, TransactionStatus } from "@ledgerhq/live-common/families/ton/types"; +import { Account } from "@ledgerhq/types-live"; +import invariant from "invariant"; +import React, { useCallback } from "react"; +import { useTranslation } from "react-i18next"; +import Input from "~/renderer/components/Input"; + +const CommentField = ({ + onChange, + account, + transaction, + status, +}: { + onChange: (a: Transaction) => void; + account: Account; + transaction: Transaction; + status: TransactionStatus; +}) => { + invariant(transaction.family === "ton", "Comment: TON family expected"); + + const { t } = useTranslation(); + + const bridge = getAccountBridge(account); + + const onCommentFieldChange = useCallback( + (value: string) => { + onChange( + bridge.updateTransaction(transaction, { + comment: { isEncrypted: false, text: value ?? "" }, + }), + ); + }, + [onChange, transaction, bridge], + ); + + // We use transaction as an error here. + // on the ledger-live mobile + return ( + + ); +}; + +export default CommentField; diff --git a/apps/ledger-live-desktop/src/renderer/families/ton/SendRecipientFields.tsx b/apps/ledger-live-desktop/src/renderer/families/ton/SendRecipientFields.tsx new file mode 100644 index 000000000000..9872ce458d1b --- /dev/null +++ b/apps/ledger-live-desktop/src/renderer/families/ton/SendRecipientFields.tsx @@ -0,0 +1,41 @@ +import { Transaction, TransactionStatus } from "@ledgerhq/live-common/families/ton/types"; +import { Account } from "@ledgerhq/types-live"; +import React from "react"; +import { Trans } from "react-i18next"; +import Box from "~/renderer/components/Box"; +import Label from "~/renderer/components/Label"; +import LabelInfoTooltip from "~/renderer/components/LabelInfoTooltip"; +import CommentField from "./CommentField"; + +const Root = (props: { + account: Account; + transaction: Transaction; + status: TransactionStatus; + onChange: (a: Transaction) => void; + trackProperties?: object; +}) => { + return ( + + + + + + + + + + + ); +}; +export default { + component: Root, + // Transaction is used here to prevent user to forward + // If he format a comment incorrectly + fields: ["comment", "transaction"], +}; diff --git a/apps/ledger-live-desktop/src/renderer/families/ton/index.ts b/apps/ledger-live-desktop/src/renderer/families/ton/index.ts new file mode 100644 index 000000000000..b008483ca834 --- /dev/null +++ b/apps/ledger-live-desktop/src/renderer/families/ton/index.ts @@ -0,0 +1,27 @@ +import { + TonOperation, + Transaction, + TransactionStatus, +} from "@ledgerhq/live-common/families/ton/types"; +import { Account } from "@ledgerhq/types-live"; +import { LLDCoinFamily } from "../types"; +import AccountSubHeader from "./AccountSubHeader"; +import sendRecipientFields from "./SendRecipientFields"; +import operationDetails from "./operationDetails"; + +const family: LLDCoinFamily = { + operationDetails, + AccountSubHeader, + sendRecipientFields, + getTransactionExplorer: (explorerView, operation) => + explorerView && + explorerView.tx && + explorerView.tx.replace( + "$hash", + operation.extra.explorerHash && operation.extra.explorerHash !== "" + ? operation.extra.explorerHash + : `by-msg-hash/${operation.hash}`, + ), +}; + +export default family; diff --git a/apps/ledger-live-desktop/src/renderer/families/ton/operationDetails.tsx b/apps/ledger-live-desktop/src/renderer/families/ton/operationDetails.tsx new file mode 100644 index 000000000000..4d83de4576ac --- /dev/null +++ b/apps/ledger-live-desktop/src/renderer/families/ton/operationDetails.tsx @@ -0,0 +1,31 @@ +import { TonOperation } from "@ledgerhq/live-common/families/ton/types"; +import React from "react"; +import { Trans } from "react-i18next"; +import Ellipsis from "~/renderer/components/Ellipsis"; +import { + OpDetailsData, + OpDetailsSection, + OpDetailsTitle, +} from "~/renderer/drawers/OperationDetails/styledComponents"; + +type OperationDetailsExtraProps = { + operation: TonOperation; +}; + +const OperationDetailsExtra = ({ operation }: OperationDetailsExtraProps) => { + const { extra } = operation; + return !extra.comment.text ? null : ( + + + + + + {extra.comment.text} + + + ); +}; + +export default { + OperationDetailsExtra, +}; diff --git a/apps/ledger-live-desktop/src/renderer/modals/AddAccounts/steps/StepChooseCurrency.tsx b/apps/ledger-live-desktop/src/renderer/modals/AddAccounts/steps/StepChooseCurrency.tsx index 535310839afb..639ce7ccf863 100644 --- a/apps/ledger-live-desktop/src/renderer/modals/AddAccounts/steps/StepChooseCurrency.tsx +++ b/apps/ledger-live-desktop/src/renderer/modals/AddAccounts/steps/StepChooseCurrency.tsx @@ -80,6 +80,7 @@ const StepChooseCurrency = ({ currency, setCurrency }: StepProps) => { const scroll = useFeature("currencyScroll"); const scrollSepolia = useFeature("currencyScrollSepolia"); const icon = useFeature("currencyIcon"); + const ton = useFeature("currencyTon"); const featureFlaggedCurrencies = useMemo( (): Partial | null>> => ({ @@ -122,6 +123,7 @@ const StepChooseCurrency = ({ currency, setCurrency }: StepProps) => { neon_evm: neonEvm, lukso, linea, + ton, linea_sepolia: lineaSepolia, blast, blast_sepolia: blastSepolia, @@ -169,6 +171,7 @@ const StepChooseCurrency = ({ currency, setCurrency }: StepProps) => { neonEvm, lukso, linea, + ton, lineaSepolia, blast, blastSepolia, diff --git a/apps/ledger-live-desktop/static/i18n/en/app.json b/apps/ledger-live-desktop/static/i18n/en/app.json index 0cef4f748299..35047370b80e 100644 --- a/apps/ledger-live-desktop/static/i18n/en/app.json +++ b/apps/ledger-live-desktop/static/i18n/en/app.json @@ -5174,6 +5174,10 @@ "memo": "Memo", "memoWarningText": "When using a Memo, carefully verify the type used with the recipient" }, + "ton": { + "commentPlaceholder": "Optional", + "comment": "Comment" + }, "stellar": { "memo": "Memo", "memoType": { @@ -5720,6 +5724,9 @@ "title": "Sequence number error", "description": "Please close the window and try again later" }, + "TonCommentInvalid": { + "title": "Comment must not exceed 120 characters without special characters" + }, "CantScanQRCode": { "title": "Couldn't scan this QR code: auto-verification not supported by this address" }, diff --git a/apps/ledger-live-mobile/babel.config.js b/apps/ledger-live-mobile/babel.config.js index d9162952346b..6c35be935593 100644 --- a/apps/ledger-live-mobile/babel.config.js +++ b/apps/ledger-live-mobile/babel.config.js @@ -12,6 +12,8 @@ module.exports = { "@babel/plugin-transform-named-capturing-groups-regex", "@babel/plugin-proposal-export-namespace-from", "@babel/plugin-transform-class-static-block", + "@babel/plugin-transform-flow-strip-types", + ["@babel/plugin-transform-private-methods", { loose: true }], "react-native-reanimated/plugin", // react-native-reanimated/plugin has to be listed last. ], }; diff --git a/apps/ledger-live-mobile/ios/Podfile.lock b/apps/ledger-live-mobile/ios/Podfile.lock index b074a321eefd..20e63575bfe3 100644 --- a/apps/ledger-live-mobile/ios/Podfile.lock +++ b/apps/ledger-live-mobile/ios/Podfile.lock @@ -47,6 +47,8 @@ PODS: - React-NativeModulesApple - React-RCTAppDelegate - ReactCommon/turbomodule/core + - ExpoRandom (13.6.0): + - ExpoModulesCore - FBLazyVector (0.73.6) - FBReactNativeSpec (0.73.6): - RCT-Folly (= 2022.05.16.00) @@ -1098,6 +1100,8 @@ PODS: - React-Core - react-native-fast-crypto (2.2.0): - React + - react-native-fast-pbkdf2 (0.3.1): + - React-Core - react-native-flipper (0.163.0): - React-Core - react-native-flipper-performance-plugin (0.4.0): @@ -1418,6 +1422,7 @@ DEPENDENCIES: - "ExpoImageManipulator (from `../../../node_modules/.pnpm/expo-image-manipulator@11.8.0_expo-modules-core@1.11.12_react-native@0.73.6_@babel+core@7.24._sgbzbk7nfhtlihtns5cja4huei/node_modules/expo-image-manipulator/ios`)" - "ExpoKeepAwake (from `../../../node_modules/.pnpm/expo-keep-awake@12.8.2_expo-modules-core@1.11.12_react-native@0.73.6_@babel+core@7.24.3_react_gqhplzyroote7enqgwhytprwhq/node_modules/expo-keep-awake/ios`)" - "ExpoModulesCore (from `../../../node_modules/.pnpm/expo-modules-core@1.11.12_react-native@0.73.6_@babel+core@7.24.3_react@18.2.0__react@18.2.0/node_modules/expo-modules-core`)" + - "ExpoRandom (from `../../../node_modules/.pnpm/expo-random@13.6.0_expo-modules-core@1.11.12_react-native@0.73.6_@babel+core@7.24.3_react@18._74hzmsxcfy4hq2gp3ztpqsecuu/node_modules/expo-random/ios`)" - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector`) - FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`) - Flipper (= 0.201.0) @@ -1474,6 +1479,7 @@ DEPENDENCIES: - react-native-ble-plx (from `../node_modules/react-native-ble-plx`) - react-native-config (from `../node_modules/react-native-config`) - react-native-fast-crypto (from `../node_modules/react-native-fast-crypto`) + - react-native-fast-pbkdf2 (from `../node_modules/react-native-fast-pbkdf2`) - react-native-flipper (from `../node_modules/react-native-flipper`) - react-native-flipper-performance-plugin (from `../node_modules/react-native-flipper-performance-plugin`) - react-native-get-random-values (from `../node_modules/react-native-get-random-values`) @@ -1607,6 +1613,8 @@ EXTERNAL SOURCES: :path: "../../../node_modules/.pnpm/expo-keep-awake@12.8.2_expo-modules-core@1.11.12_react-native@0.73.6_@babel+core@7.24.3_react_gqhplzyroote7enqgwhytprwhq/node_modules/expo-keep-awake/ios" ExpoModulesCore: :path: "../../../node_modules/.pnpm/expo-modules-core@1.11.12_react-native@0.73.6_@babel+core@7.24.3_react@18.2.0__react@18.2.0/node_modules/expo-modules-core" + ExpoRandom: + :path: "../../../node_modules/.pnpm/expo-random@13.6.0_expo-modules-core@1.11.12_react-native@0.73.6_@babel+core@7.24.3_react@18._74hzmsxcfy4hq2gp3ztpqsecuu/node_modules/expo-random/ios" FBLazyVector: :path: "../node_modules/react-native/Libraries/FBLazyVector" FBReactNativeSpec: @@ -1670,6 +1678,8 @@ EXTERNAL SOURCES: :path: "../node_modules/react-native-config" react-native-fast-crypto: :path: "../node_modules/react-native-fast-crypto" + react-native-fast-pbkdf2: + :path: "../node_modules/react-native-fast-pbkdf2" react-native-flipper: :path: "../node_modules/react-native-flipper" react-native-flipper-performance-plugin: @@ -1818,6 +1828,7 @@ SPEC CHECKSUMS: ExpoImageManipulator: c1d7cb865eacd620a35659f3da34c70531f10b59 ExpoKeepAwake: 0f5cad99603a3268e50af9a6eb8b76d0d9ac956c ExpoModulesCore: 61dc57c6e2a35f2f84baf488146db624e03af4cd + ExpoRandom: f0cd58e154e463d913462f3b445870b12d1c2f12 FBLazyVector: f64d1e2ea739b4d8f7e4740cde18089cd97fe864 FBReactNativeSpec: 7351d9daa8a692bc3af6eb00a56e4cdb07403431 Firebase: 5f8193dff4b5b7c5d5ef72ae54bb76c08e2b841d @@ -1844,7 +1855,7 @@ SPEC CHECKSUMS: libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009 lottie-ios: fcb5e73e17ba4c983140b7d21095c834b3087418 lottie-react-native: 13cd0c4782c3e6bb26bfa4cc2d08bfb84f6d1ab6 - MultiplatformBleAdapter: b1fddd0d499b96b607e00f0faa8e60648343dc1d + MultiplatformBleAdapter: ea8bac405ec200d0ca9de0f89afef6f06fb2abbc nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96 OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47 @@ -1874,6 +1885,7 @@ SPEC CHECKSUMS: react-native-ble-plx: c040d0123518e121bf4cda02061bf72644f68d15 react-native-config: 86038147314e2e6d10ea9972022aa171e6b1d4d8 react-native-fast-crypto: 5943c42466b86ad70be60d3a5f64bd22251e5d9e + react-native-fast-pbkdf2: 44d6ffa0346863e14100294004a1595ec76b2e9f react-native-flipper: 2d552a8178d839ef378220101fb7f0cd5b2a8003 react-native-flipper-performance-plugin: 42ec5017abd26e7c5a1f527f2db92c14a90cabdb react-native-get-random-values: 21325b2244dfa6b58878f51f9aa42821e7ba3d06 diff --git a/apps/ledger-live-mobile/package.json b/apps/ledger-live-mobile/package.json index a12b392987d5..5cbe844af72d 100644 --- a/apps/ledger-live-mobile/package.json +++ b/apps/ledger-live-mobile/package.json @@ -145,6 +145,7 @@ "expo-keep-awake": "~12.8.2", "expo-modules-autolinking": "^1.10.2", "expo-modules-core": "^1.11.8", + "expo-random": "^13.6.0", "fuse.js": "^6.4.6", "hoist-non-react-statics": "3.3.2", "i18next": "20.6.1", @@ -171,6 +172,7 @@ "react-native-extra-dimensions-android": "^1.2.5", "react-native-fast-crypto": "^2.2.0", "react-native-fast-image": "^8.5.11", + "react-native-fast-pbkdf2": "^0.3.1", "react-native-gesture-handler": "^2.9.0", "react-native-get-random-values": "^1.11.0", "react-native-haptic-feedback": "^2.0.3", 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 ed3e52360107..579d8c69d1ce 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/SendFundsNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/SendFundsNavigator.ts @@ -35,6 +35,7 @@ import type { Transaction as ICPTransaction } from "@ledgerhq/live-common/famili 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 TonTransaction } from "@ledgerhq/live-common/families/ton/types"; import BigNumber from "bignumber.js"; import { Result } from "@ledgerhq/live-common/bridge/useBridgeTransaction"; import { ScreenName } from "~/const"; @@ -344,4 +345,18 @@ export type SendFundsNavigatorStackParamList = { | ScreenName.SendSelectDevice | ScreenName.SwapForm; }; + [ScreenName.TonEditComment]: { + accountId: string; + account: Account; + parentId?: string; + transaction: TonTransaction; + 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/SignTransactionNavigator.ts b/apps/ledger-live-mobile/src/components/RootNavigator/types/SignTransactionNavigator.ts index 98f6f6940c5e..83371f35a83c 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/SignTransactionNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/SignTransactionNavigator.ts @@ -31,6 +31,7 @@ import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/fam 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 TonTransaction } from "@ledgerhq/live-common/families/ton/types"; import { Device } from "@ledgerhq/live-common/hw/actions/types"; import { Account, Operation, SignedOperation } from "@ledgerhq/types-live"; import BigNumber from "bignumber.js"; @@ -310,4 +311,18 @@ export type SignTransactionNavigatorParamList = { | ScreenName.SendSelectDevice | ScreenName.SwapForm; }; + [ScreenName.TonEditComment]: { + accountId: string; + account: Account; + parentId?: string; + transaction: TonTransaction; + 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 cfdf9a08788a..fabdb2249ade 100644 --- a/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts +++ b/apps/ledger-live-mobile/src/components/RootNavigator/types/SwapNavigator.ts @@ -41,6 +41,7 @@ import type { Transaction as ICPTransaction } from "@ledgerhq/live-common/famili 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 TonTransaction } from "@ledgerhq/live-common/families/ton/types"; import BigNumber from "bignumber.js"; import { Account, Operation } from "@ledgerhq/types-live"; import { ScreenName } from "~/const"; @@ -314,4 +315,18 @@ export type SwapNavigatorParamList = { | ScreenName.SendSelectDevice | ScreenName.SwapForm; }; + [ScreenName.TonEditComment]: { + accountId: string; + account: Account; + parentId?: string; + transaction: TonTransaction; + 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 2b81da03310a..8b183cfc3c12 100644 --- a/apps/ledger-live-mobile/src/const/navigation.ts +++ b/apps/ledger-live-mobile/src/const/navigation.ts @@ -311,6 +311,9 @@ export enum ScreenName { // internet_computer InternetComputerEditMemo = "InternetComputerEditMemo", + // ton + TonEditComment = "TonEditComment", + // crypto_org CryptoOrgEditMemo = "CryptoOrgEditMemo", diff --git a/apps/ledger-live-mobile/src/families/index.ts b/apps/ledger-live-mobile/src/families/index.ts index 546e1c6eb966..c272b073973f 100644 --- a/apps/ledger-live-mobile/src/families/index.ts +++ b/apps/ledger-live-mobile/src/families/index.ts @@ -17,3 +17,4 @@ export * from "./casper"; export * from "./stellar"; export * from "./tezos"; export * from "./tron"; +export * from "./ton"; diff --git a/apps/ledger-live-mobile/src/families/ton/AccountSubHeader.tsx b/apps/ledger-live-mobile/src/families/ton/AccountSubHeader.tsx new file mode 100644 index 000000000000..c4dc2c5f22c0 --- /dev/null +++ b/apps/ledger-live-mobile/src/families/ton/AccountSubHeader.tsx @@ -0,0 +1,6 @@ +import React from "react"; +import AccountSubHeader from "~/components/AccountSubHeader"; + +export default function TonAccountSubHeader() { + return ; +} diff --git a/apps/ledger-live-mobile/src/families/ton/ScreenEditComment.tsx b/apps/ledger-live-mobile/src/families/ton/ScreenEditComment.tsx new file mode 100644 index 000000000000..99990cf4aa3b --- /dev/null +++ b/apps/ledger-live-mobile/src/families/ton/ScreenEditComment.tsx @@ -0,0 +1,120 @@ +import invariant from "invariant"; +import React, { useCallback, useState } from "react"; +import { View, StyleSheet, ScrollView } from "react-native"; +import { SafeAreaView } from "react-native-safe-area-context"; +import { useSelector } from "react-redux"; +import { useTranslation } from "react-i18next"; +import i18next from "i18next"; +import { getAccountBridge } from "@ledgerhq/live-common/bridge/index"; +import { useIsFocused, useTheme } from "@react-navigation/native"; +import KeyboardView from "~/components/KeyboardView"; +import Button from "~/components/Button"; +import { ScreenName } from "~/const"; +import { accountScreenSelector } from "~/reducers/accounts"; +import TextInput from "~/components/FocusedTextInput"; +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"; + +type NavigationProps = BaseComposite< + StackNavigatorProps< + SendFundsNavigatorStackParamList | SignTransactionNavigatorParamList | SwapNavigatorParamList, + ScreenName.TonEditComment + > +>; + +function TonEditComment({ navigation, route }: NavigationProps) { + const isFocused = useIsFocused(); + const { colors } = useTheme(); + const { t } = useTranslation(); + const { account } = useSelector(accountScreenSelector(route)); + invariant(account, "account is required"); + const [comment, setComment] = useState( + !route.params.transaction.comment.isEncrypted ? route.params.transaction.comment.text : "", + ); + const onChangeCommentValue = useCallback((str: string) => { + setComment(str); + }, []); + const onValidateText = 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, { + comment: { isEncrypted: false, text: comment }, + }), + }); + }, [navigation, route.params, account, comment]); + return ( + + + + {isFocused && ( + + )} + + +