Skip to content

Commit

Permalink
fix(LLD, LLM): token summary and device screens
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhd authored and Justkant committed Nov 4, 2024
1 parent 6664c37 commit 1a949f0
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 40 deletions.
2 changes: 2 additions & 0 deletions apps/ledger-live-desktop/src/config/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const supportLinkByTokenType = {
trc20: "https://support.ledger.com/article/360013062159-zd",
asa: "https://support.ledger.com/article/360015896040-zd",
nfts: "https://support.ledger.com/article/4404389453841-zd",
// spl: "Solana spl tokens. TODO: to be defined",
};

const errors: Record<string, string> = {
Expand Down Expand Up @@ -153,6 +154,7 @@ export const urls = {
},
solana: {
staking: "https://support.ledger.com/article/4731749170461-zd",
splTokenInfo: "Solana spl tokens link TODO: to be defined",
recipient_info: "https://support.ledger.com",
ledgerByFigmentTC:
"https://cdn.figment.io/legal/Current%20Ledger_Online%20Staking%20Delgation%20Services%20Agreement.pdf",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useMemo } from "react";
import { getDeviceTransactionConfig } from "@ledgerhq/live-common/transaction/index";
import { SolanaFamily } from "./types";
import Alert from "~/renderer/components/Alert";
import { Trans } from "react-i18next";
import ConfirmTitle from "~/renderer/components/TransactionConfirm/ConfirmTitle";
import LinkWithExternalIcon from "~/renderer/components/LinkWithExternalIcon";
import Box from "~/renderer/components/Box";
import { openURL } from "~/renderer/linking";
import { useLocalizedUrl } from "~/renderer/hooks/useLocalizedUrls";
import { urls } from "~/config/urls";

const Title: TitleComponent = props => {
const { transaction, account, parentAccount, status } = props;
const transferTokenHelpUrl = useLocalizedUrl(urls.solana.splTokenInfo);

const fields = getDeviceTransactionConfig({
account,
parentAccount,
transaction,
status,
});

const typeTransaction: string | undefined = useMemo(() => {
const typeField = fields.find(field => field.label && field.label === "Type");

if (typeField && typeField.type === "text" && typeField.value) {
return typeField.value;
}
}, [fields]);

if (transaction.model.commandDescriptor?.command.kind === "token.transfer") {
return (
<Box
flexDirection="column"
alignItems="center"
gap={4}
mb={4}
justifyContent="center"
className="title-test-transfer"
>
<ConfirmTitle title={undefined} typeTransaction={typeTransaction} {...props} />
<Alert type="warning">
<Trans i18nKey="solana.token.transferWarning">
<LinkWithExternalIcon
color="palette.warning.c60"
onClick={() => openURL(transferTokenHelpUrl)}
/>
</Trans>
</Alert>
</Box>
);
}

return <ConfirmTitle title={undefined} typeTransaction={typeTransaction} {...props} />;
};

type TransactionConfirmFields = SolanaFamily["transactionConfirmFields"];
type TitleComponent = NonNullable<NonNullable<TransactionConfirmFields>["title"]>;

const transactionConfirmFields: TransactionConfirmFields = {
// footer: Footer, // is not shown without manifestId
// fieldComponents,
title: Title,
};

export default transactionConfirmFields;
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import AccountBalanceSummaryFooter from "./AccountBalanceSummaryFooter";
import StakeBanner from "./StakeBanner";
import { SolanaFamily } from "./types";
import operationDetails from "./operationDetails";
import transactionConfirmFields from "./TransactionConfirmFields";

const family: SolanaFamily = {
accountHeaderManageActions,
Expand All @@ -15,6 +16,7 @@ const family: SolanaFamily = {
AccountBalanceSummaryFooter,
StakeBanner,
operationDetails,
transactionConfirmFields,
};

export default family;
3 changes: 2 additions & 1 deletion apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3719,7 +3719,8 @@
}
},
"token": {
"frozenStateWarning": "Account assets are frozen!"
"frozenStateWarning": "Account assets are frozen!",
"transferWarning": "Solana SPL tokens transactions have unique characteristics. To learn more, visit: <0>ledger.com/spl</0>"
}
},
"ethereum": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import invariant from "invariant";
import React from "react";
import { Linking, View } from "react-native";
import { Trans } from "react-i18next";
import { Link } from "@ledgerhq/native-ui";
import { DeviceTransactionField } from "@ledgerhq/live-common/transaction/index";
import {
SolanaAccount,
SolanaTokenAccount,
Transaction,
TransactionStatus,
} from "@ledgerhq/live-common/families/solana/types";
import Alert from "~/components/Alert";
import { urls } from "~/utils/urls";
import LText from "~/components/LText";

type SolanaFieldComponentProps = {
account: SolanaAccount | SolanaTokenAccount;
parentAccount: SolanaAccount | undefined | null;
transaction: Transaction;
status: TransactionStatus;
field: DeviceTransactionField;
};

const Warning = ({ transaction }: SolanaFieldComponentProps) => {
invariant(transaction.family === "solana", "solana transaction");
if (transaction.model.commandDescriptor?.command.kind === "token.transfer") {
return (
<View>
<Alert type="hint">
<LText>
<Trans i18nKey="solana.token.transferWarning">
<Link onPress={() => Linking.openURL(urls.solana.splTokenInfo)} type="color" />
</Trans>
</LText>
</Alert>
</View>
);
}
return null;
};

export default {
warning: Warning,
fieldComponents: {},
};
3 changes: 2 additions & 1 deletion apps/ledger-live-mobile/src/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -5914,7 +5914,8 @@
"reserveWarning": "Please ensure you reserve at least {{amount}} SOL in your wallet to cover future network fees to deactivate and withdraw your stake"
},
"token": {
"frozenStateWarning": "Account assets are frozen!"
"frozenStateWarning": "Account assets are frozen!",
"transferWarning": "Double-check the transaction details on your Ledger device before signing. Solana SPL tokens transactions have unique characteristics. To learn more, visit: <0>ledger.com/spl</0>"
}
},
"near": {
Expand Down
1 change: 1 addition & 0 deletions apps/ledger-live-mobile/src/utils/urls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export const urls = {
solana: {
supportPage: "https://support.ledger.com",
stakingPage: "https://support.ledger.com/article/4731749170461-zd",
splTokenInfo: "Solana spl tokens link TODO: to be defined",
},
resources: {
gettingStarted:
Expand Down
44 changes: 6 additions & 38 deletions libs/coin-modules/coin-solana/src/deviceTransactionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,55 +70,23 @@ function fieldsForTransfer(_command: TransferCommand): DeviceTransactionField[]
return fields;
}

function fieldsForTokenTransfer(command: TokenTransferCommand): DeviceTransactionField[] {
function fieldsForTokenTransfer(_command: TokenTransferCommand): DeviceTransactionField[] {
const fields: Array<DeviceTransactionField> = [];

if (command.recipientDescriptor.shouldCreateAsAssociatedTokenAccount) {
fields.push({
type: "address",
label: "Create token acct",
address: command.recipientDescriptor.tokenAccAddress,
});

fields.push({
type: "address",
label: "From mint",
address: command.mintAddress,
});
fields.push({
type: "address",
label: "Funded by",
address: command.ownerAddress,
});
}

fields.push({
type: "amount",
label: "Transfer tokens",
});

fields.push({
type: "address",
address: command.mintAddress,
label: "Mint",
});

fields.push({
type: "address",
address: command.ownerAssociatedTokenAccountAddress,
label: "From",
});

fields.push({
type: "address",
address: command.ownerAddress,
label: "Owner",
type: "text",
value: "Solana",
label: "Network",
});

fields.push({
type: "address",
address: command.ownerAddress,
label: "Fee payer",
type: "fees",
label: "Max network fees",
});

return fields;
Expand Down

0 comments on commit 1a949f0

Please sign in to comment.