-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(llm): π·οΈ add memo/tag input in some coins send flow (#8155)
* feat(llm): add the memo tag input * feat(llm): add the memo tag drawer * feat(llm): use coin specific memo tag input via useMemoTagInput * feat(llm): add a TON "comment" field in the recipient step * feat(llm): add an ICP memo input in the recipient step * feat(llm): add XRP tag input to the recipient step * chore(llm): simplify each coin specific MemoTagInput * feat(llm): add the memo tag input on a bunch of coins * chore: update change log * chore(llm): create a GenericMemoTagInput component to reduce the boilerplate on each coin * chore(llm): store the memo tag drawer state in an enum
- Loading branch information
Showing
19 changed files
with
338 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"live-mobile": minor | ||
--- | ||
|
||
Add memo/tag input in some coins send flow |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
apps/ledger-live-mobile/src/families/algorand/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
import type { Transaction as AlgorandTransaction } from "@ledgerhq/live-common/families/algorand/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => ( | ||
<GenericMemoTagInput<AlgorandTransaction> | ||
{...props} | ||
valueToTxPatch={value => ({ memo: value || undefined })} | ||
/> | ||
); |
12 changes: 12 additions & 0 deletions
12
apps/ledger-live-mobile/src/families/cardano/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
import type { Transaction as CardanoTransaction } from "@ledgerhq/live-common/families/cardano/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => ( | ||
<GenericMemoTagInput<CardanoTransaction> | ||
{...props} | ||
valueToTxPatch={value => ({ memo: value || undefined })} | ||
/> | ||
); |
18 changes: 18 additions & 0 deletions
18
apps/ledger-live-mobile/src/families/casper/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/families/casper/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<GenericMemoTagInput<CasperTransaction> | ||
{...props} | ||
textToValue={text => text.replace(/\D/g, "")} | ||
valueToTxPatch={value => ({ transferId: value || undefined })} | ||
placeholder={t("send.summary.transferId")} | ||
/> | ||
); | ||
}; |
12 changes: 12 additions & 0 deletions
12
apps/ledger-live-mobile/src/families/cosmos/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
import type { Transaction as CosmosTransaction } from "@ledgerhq/live-common/families/cosmos/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => ( | ||
<GenericMemoTagInput<CosmosTransaction> | ||
{...props} | ||
valueToTxPatch={value => ({ memo: value || undefined })} | ||
/> | ||
); |
12 changes: 12 additions & 0 deletions
12
apps/ledger-live-mobile/src/families/crypto_org/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
import type { Transaction as CryptoOrgTransaction } from "@ledgerhq/live-common/families/crypto_org/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => ( | ||
<GenericMemoTagInput<CryptoOrgTransaction> | ||
{...props} | ||
valueToTxPatch={value => ({ memo: value || undefined })} | ||
/> | ||
); |
12 changes: 12 additions & 0 deletions
12
apps/ledger-live-mobile/src/families/hedera/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
import type { Transaction as HederaTransaction } from "@ledgerhq/live-common/families/hedera/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => ( | ||
<GenericMemoTagInput<HederaTransaction> | ||
{...props} | ||
valueToTxPatch={value => ({ memo: value || undefined })} | ||
/> | ||
); |
13 changes: 13 additions & 0 deletions
13
apps/ledger-live-mobile/src/families/internet_computer/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from "react"; | ||
|
||
import { Transaction as ICPTransaction } from "@ledgerhq/live-common/families/internet_computer/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => ( | ||
<GenericMemoTagInput<ICPTransaction> | ||
{...props} | ||
textToValue={text => text.replace(/\D/g, "")} | ||
valueToTxPatch={value => ({ memo: value || undefined })} | ||
/> | ||
); |
12 changes: 12 additions & 0 deletions
12
apps/ledger-live-mobile/src/families/solana/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
import { Transaction as SolanaTransaction } from "@ledgerhq/live-common/generated/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => ( | ||
<GenericMemoTagInput<SolanaTransaction> | ||
{...props} | ||
valueToTxPatch={value => ({ memo: value || undefined })} | ||
/> | ||
); |
12 changes: 12 additions & 0 deletions
12
apps/ledger-live-mobile/src/families/stacks/MemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from "react"; | ||
|
||
import type { Transaction as StacksTransaction } from "@ledgerhq/live-common/families/stacks/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => ( | ||
<GenericMemoTagInput<StacksTransaction> | ||
{...props} | ||
valueToTxPatch={value => ({ memo: value || undefined })} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import type { Transaction as TonTransaction } from "@ledgerhq/live-common/families/ton/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<GenericMemoTagInput<TonTransaction> | ||
{...props} | ||
valueToTxPatch={value => | ||
value ? { comment: { isEncrypted: false, text: value } } : { comment: undefined } | ||
} | ||
placeholder={t("send.summary.comment")} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/families/xrp/types"; | ||
import type { MemoTagInputProps } from "LLM/features/MemoTag/types"; | ||
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput"; | ||
|
||
export default (props: MemoTagInputProps) => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<GenericMemoTagInput<RippleTransaction> | ||
{...props} | ||
textToValue={text => text.replace(/\D/g, "")} | ||
valueToTxPatch={value => ({ tag: value ? Number(value) : undefined })} | ||
placeholder={t("send.summary.tag")} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
apps/ledger-live-mobile/src/newArch/features/MemoTag/components/GenericMemoTagInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from "react"; | ||
|
||
import type { Transaction } from "@ledgerhq/live-common/generated/types"; | ||
import { AnimatedInput } from "@ledgerhq/native-ui"; | ||
import { MemoTagInputProps } from "../types"; | ||
|
||
type Props<T extends Transaction = Transaction> = MemoTagInputProps<T> & { | ||
textToValue?: (text: string) => string; | ||
valueToTxPatch: (text: string) => Partial<T>; | ||
}; | ||
|
||
export function GenericMemoTagInput<T extends Transaction>({ | ||
onChange, | ||
valueToTxPatch, | ||
textToValue, | ||
...inputProps | ||
}: Props<T>) { | ||
const [value, setValue] = React.useState(""); | ||
|
||
const handleChange = (text: string) => { | ||
const value = textToValue?.(text) ?? text; | ||
const patch = valueToTxPatch(value); | ||
setValue(value); | ||
onChange({ value, patch }); | ||
}; | ||
|
||
return <AnimatedInput {...inputProps} value={value} onChangeText={handleChange} />; | ||
} |
57 changes: 57 additions & 0 deletions
57
apps/ledger-live-mobile/src/newArch/features/MemoTag/components/MemoTagDrawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useTheme } from "styled-components/native"; | ||
import React, { memo } from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import { Linking } from "react-native"; | ||
import { Flex, Icons, Text } from "@ledgerhq/native-ui"; | ||
import Button from "~/components/Button"; | ||
import Circle from "~/components/Circle"; | ||
import QueuedDrawer from "~/components/QueuedDrawer"; | ||
import { urls } from "~/utils/urls"; | ||
|
||
type Props = { | ||
open: boolean; | ||
onClose: () => void; | ||
onNext: () => void; | ||
}; | ||
|
||
export const MemoTagDrawer = memo(({ open, onClose, onNext }: Props) => { | ||
const { colors } = useTheme(); | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<QueuedDrawer isRequestingToBeOpened={open} onClose={onClose}> | ||
<Flex alignItems="center" mb={7}> | ||
<Circle size={72} bg={colors.opacityDefault.c05}> | ||
<Icons.InformationFill size="L" color="primary.c80" /> | ||
</Circle> | ||
</Flex> | ||
|
||
<Text variant="h4" textAlign="center" mb={6}> | ||
{t("transfer.receive.memoTag.title")} | ||
</Text> | ||
|
||
<Text variant="bodyLineHeight" textAlign="center" color="neutral.c80" mb={8}> | ||
{t("transfer.receive.memoTag.description")} | ||
</Text> | ||
|
||
<Button type="primary" title={t("transfer.memoTag.cta")} onPress={onClose} mb={3} /> | ||
|
||
<Button | ||
type="tertiary" | ||
title={t("transfer.memoTag.ignore")} | ||
onPress={onNext} | ||
outline | ||
mb={3} | ||
/> | ||
|
||
<Button | ||
type="accent" | ||
size="large" | ||
Icon={() => <Icons.ExternalLink size="S" color="primary.c80" />} | ||
onPress={() => Linking.openURL(urls.memoTag)} | ||
> | ||
{t("transfer.memoTag.learnMore")} | ||
</Button> | ||
</QueuedDrawer> | ||
); | ||
}); |
30 changes: 30 additions & 0 deletions
30
apps/ledger-live-mobile/src/newArch/features/MemoTag/hooks/useMemoTagInput.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { FC, useCallback, useState } from "react"; | ||
|
||
import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; | ||
import { Transaction } from "@ledgerhq/live-common/generated/types"; | ||
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets"; | ||
import perFamily from "~/generated/MemoTagInput"; | ||
import { MemoTagInputProps } from "../types"; | ||
|
||
export const useMemoTagInput = ( | ||
family: CryptoCurrency["family"], | ||
updateTransaction: (patch: Partial<Transaction>) => void, | ||
) => { | ||
const featureMemoTag = useFeature("llmMemoTag"); | ||
const Input: FC<MemoTagInputProps> | null = | ||
(featureMemoTag?.enabled && | ||
family in perFamily && | ||
perFamily[family as keyof typeof perFamily]) || | ||
null; | ||
|
||
const [isEmpty, setIsEmpty] = useState(true); | ||
const handleChange = useCallback<MemoTagInputProps["onChange"]>( | ||
({ patch, value }) => { | ||
setIsEmpty(!value); | ||
updateTransaction(patch); | ||
}, | ||
[updateTransaction], | ||
); | ||
|
||
return Input && { Input, isEmpty, handleChange }; | ||
}; |
7 changes: 7 additions & 0 deletions
7
apps/ledger-live-mobile/src/newArch/features/MemoTag/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { Transaction } from "@ledgerhq/live-common/generated/types"; | ||
import type { AnimatedInputProps } from "@ledgerhq/native-ui/components/Form/Input/AnimatedInput"; | ||
|
||
export type MemoTagInputProps<T extends Transaction = Transaction> = Omit< | ||
AnimatedInputProps, | ||
"value" | "onChangeText" | "onChange" | ||
> & { onChange: (update: { patch: Partial<T>; value: string }) => void }; |
Oops, something went wrong.
bb6dfe4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Bot] Bitcoin on Staging ($0.00) β² 51s
13 critical spec errors
Spec Bitcoin failed!
Spec Bitcoin Testnet failed!
Spec Bitcoin Cash failed!
Spec Bitcoin Gold failed!
Spec Dash failed!
Spec Digibyte failed!
Spec DogeCoin failed!
Spec Komodo failed!
Spec Litecoin failed!
Spec Qtum failed!
Spec ZCash failed!
Spec Horizen failed!
Spec Decred failed!
Details of the 0 mutations
Spec Bitcoin (failed)
Spec Bitcoin Testnet (failed)
Spec Bitcoin Cash (failed)
Spec Bitcoin Gold (failed)
Spec Dash (failed)
Spec Digibyte (failed)
Spec DogeCoin (failed)
Spec Komodo (failed)
Spec Litecoin (failed)
Spec Qtum (failed)
Spec ZCash (failed)
Spec Horizen (failed)
Spec Decred (failed)
Details of the 65 uncovered mutations
Spec Bitcoin (5)
Spec Bitcoin Testnet (5)
Spec Bitcoin Cash (5)
Spec Bitcoin Gold (5)
Spec Dash (5)
Spec Digibyte (5)
Spec DogeCoin (5)
Spec Komodo (5)
Spec Litecoin (5)
Spec Qtum (5)
Spec ZCash (5)
Spec Horizen (5)
Spec Decred (5)
Portfolio ($0.00) β Details of the 13 currencies
Performance β² 51s
Time spent for each spec: (total across mutations)