Skip to content

Commit

Permalink
fix(llm): solana memo tag send flow
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan committed Oct 30, 2024
1 parent 96094ea commit c9ad69c
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Transaction as AlgorandTransaction } from "@ledgerhq/live-common/f
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => (
<GenericMemoTagInput<AlgorandTransaction>
export default (props: MemoTagInputProps<AlgorandTransaction>) => (
<GenericMemoTagInput
{...props}
valueToTxPatch={value => ({ memo: value || undefined })}
valueToTxPatch={value => tx => ({ ...tx, memo: value || undefined })}
/>
);
6 changes: 3 additions & 3 deletions apps/ledger-live-mobile/src/families/cardano/MemoTagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Transaction as CardanoTransaction } from "@ledgerhq/live-common/fa
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => (
<GenericMemoTagInput<CardanoTransaction>
export default (props: MemoTagInputProps<CardanoTransaction>) => (
<GenericMemoTagInput
{...props}
valueToTxPatch={value => ({ memo: value || undefined })}
valueToTxPatch={value => tx => ({ ...tx, memo: value || undefined })}
/>
);
6 changes: 3 additions & 3 deletions apps/ledger-live-mobile/src/families/casper/MemoTagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import type { Transaction as CasperTransaction } from "@ledgerhq/live-common/fam
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => {
export default (props: MemoTagInputProps<CasperTransaction>) => {
const { t } = useTranslation();
return (
<GenericMemoTagInput<CasperTransaction>
<GenericMemoTagInput
{...props}
textToValue={text => text.replace(/\D/g, "")}
valueToTxPatch={value => ({ transferId: value || undefined })}
valueToTxPatch={value => tx => ({ ...tx, transferId: value || undefined })}
placeholder={t("send.summary.transferId")}
/>
);
Expand Down
6 changes: 3 additions & 3 deletions apps/ledger-live-mobile/src/families/cosmos/MemoTagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Transaction as CosmosTransaction } from "@ledgerhq/live-common/fam
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => (
<GenericMemoTagInput<CosmosTransaction>
export default (props: MemoTagInputProps<CosmosTransaction>) => (
<GenericMemoTagInput
{...props}
valueToTxPatch={value => ({ memo: value || undefined })}
valueToTxPatch={value => tx => ({ ...tx, memo: value || undefined })}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Transaction as CryptoOrgTransaction } from "@ledgerhq/live-common/
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => (
<GenericMemoTagInput<CryptoOrgTransaction>
export default (props: MemoTagInputProps<CryptoOrgTransaction>) => (
<GenericMemoTagInput
{...props}
valueToTxPatch={value => ({ memo: value || undefined })}
valueToTxPatch={value => tx => ({ ...tx, memo: value || undefined })}
/>
);
6 changes: 3 additions & 3 deletions apps/ledger-live-mobile/src/families/hedera/MemoTagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Transaction as HederaTransaction } from "@ledgerhq/live-common/fam
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => (
<GenericMemoTagInput<HederaTransaction>
export default (props: MemoTagInputProps<HederaTransaction>) => (
<GenericMemoTagInput
{...props}
valueToTxPatch={value => ({ memo: value || undefined })}
valueToTxPatch={value => tx => ({ ...tx, memo: value || undefined })}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Transaction as ICPTransaction } from "@ledgerhq/live-common/families/in
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => (
<GenericMemoTagInput<ICPTransaction>
export default (props: MemoTagInputProps<ICPTransaction>) => (
<GenericMemoTagInput
{...props}
textToValue={text => text.replace(/\D/g, "")}
valueToTxPatch={value => ({ memo: value || undefined })}
valueToTxPatch={value => tx => ({ ...tx, memo: value || undefined })}
/>
);
11 changes: 7 additions & 4 deletions apps/ledger-live-mobile/src/families/solana/MemoTagInput.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import merge from "lodash/merge";
import React from "react";

import { Transaction as SolanaTransaction } from "@ledgerhq/live-common/generated/types";
import { Transaction as SolanaTransaction } from "@ledgerhq/live-common/families/solana/types";
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => (
<GenericMemoTagInput<SolanaTransaction>
export default (props: MemoTagInputProps<SolanaTransaction>) => (
<GenericMemoTagInput
{...props}
valueToTxPatch={value => ({ memo: value || undefined })}
valueToTxPatch={value => tx =>
merge({}, tx, { model: { uiState: { memo: value || undefined } } })
}
/>
);
6 changes: 3 additions & 3 deletions apps/ledger-live-mobile/src/families/stacks/MemoTagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import type { Transaction as StacksTransaction } from "@ledgerhq/live-common/fam
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => (
<GenericMemoTagInput<StacksTransaction>
export default (props: MemoTagInputProps<StacksTransaction>) => (
<GenericMemoTagInput
{...props}
valueToTxPatch={value => ({ memo: value || undefined })}
valueToTxPatch={value => tx => ({ ...tx, memo: value || undefined })}
/>
);
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default ({ onChange }: MemoTagInputProps<StellarTransaction>) => {

const handleChange = (type: MemoType, value: string) => {
const error = isMemoValid(type, value) ? undefined : new StellarWrongMemoFormat();
const patch = { memoType: type, memoValue: value };
const patch = (tx: StellarTransaction) => ({ ...tx, memoType: type, memoValue: value });
onChange({ value, patch, error });
};

Expand Down
8 changes: 3 additions & 5 deletions apps/ledger-live-mobile/src/families/ton/MemoTagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import type { Transaction as TonTransaction } from "@ledgerhq/live-common/famili
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => {
export default (props: MemoTagInputProps<TonTransaction>) => {
const { t } = useTranslation();
return (
<GenericMemoTagInput<TonTransaction>
<GenericMemoTagInput
{...props}
valueToTxPatch={value =>
value ? { comment: { isEncrypted: false, text: value } } : { comment: undefined }
}
valueToTxPatch={value => tx => ({ ...tx, comment: { isEncrypted: false, text: value } })}
placeholder={t("send.summary.comment")}
/>
);
Expand Down
6 changes: 3 additions & 3 deletions apps/ledger-live-mobile/src/families/xrp/MemoTagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import type { Transaction as RippleTransaction } from "@ledgerhq/live-common/fam
import type { MemoTagInputProps } from "LLM/features/MemoTag/types";
import { GenericMemoTagInput } from "LLM/features/MemoTag/components/GenericMemoTagInput";

export default (props: MemoTagInputProps) => {
export default (props: MemoTagInputProps<RippleTransaction>) => {
const { t } = useTranslation();
return (
<GenericMemoTagInput<RippleTransaction>
<GenericMemoTagInput
{...props}
textToValue={text => text.replace(/\D/g, "")}
valueToTxPatch={value => ({ tag: value ? Number(value) : undefined })}
valueToTxPatch={value => tx => ({ ...tx, tag: value ? Number(value) : undefined })}
placeholder={t("send.summary.tag")}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import React from "react";

import type { Transaction } from "@ledgerhq/live-common/generated/types";
import { AnimatedInput } from "@ledgerhq/native-ui";
import { MemoTagInputProps } from "../types";
import { MemoTagInputProps, TxPatch } from "../types";

type Props<T extends Transaction = Transaction> = MemoTagInputProps<T> & {
textToValue?: (text: string) => string;
valueToTxPatch: (text: string) => Partial<T>;
valueToTxPatch: (text: string) => TxPatch<T>;
};

export function GenericMemoTagInput<T extends Transaction>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ 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";
import { MemoTagInputProps, TxPatch } from "../types";

export const useMemoTagInput = (
family: CryptoCurrency["family"],
updateTransaction: (patch: Partial<Transaction>) => void,
updateTransaction: (patch: TxPatch<Transaction>) => void,
) => {
const featureMemoTag = useFeature("llmMemoTag");
const Input: FC<MemoTagInputProps> | null =
const Input =
(featureMemoTag?.enabled &&
family in perFamily &&
perFamily[family as keyof typeof perFamily]) ||
(perFamily[family as keyof typeof perFamily] as FC<MemoTagInputProps>)) ||
null;

const [isEmpty, setIsEmpty] = useState(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Transaction } from "@ledgerhq/live-common/generated/types";
import type { AnimatedInputProps } from "@ledgerhq/native-ui/components/Form/Input/AnimatedInput";

export type TxPatch<T extends Transaction> = (tx: T) => T;

export type MemoTagInputProps<T extends Transaction = Transaction> = Omit<
AnimatedInputProps,
"value" | "onChangeText" | "onChange"
> & { onChange: (update: { patch: Partial<T>; value: string; error?: Error }) => void };
> & { onChange: (update: { patch: TxPatch<T>; value: string; error?: Error }) => void };
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default function SendSelectRecipient({ navigation, route }: Props) {
useCallback(
patch => {
const bridge = getAccountBridge(account, parentAccount);
setTransaction(bridge.updateTransaction(transaction, patch));
setTransaction(bridge.updateTransaction(transaction, patch(transaction)));
},
[account, parentAccount, setTransaction, transaction],
),
Expand Down

0 comments on commit c9ad69c

Please sign in to comment.