Skip to content

Commit

Permalink
Support/fix ada fees (#7965)
Browse files Browse the repository at this point in the history
* cardano high fees checks

* add custom CardanoFeeTooHigh error

* display feeTooHigh error

* validate protocol params

* handle fee error in delegation

* fee warning in delegation

* show tx status warnings and errors

* update

* tx error update

* sync proto params in tx prepare

* add coinconfig + update translations

* fix cc

* update texts

* add changeset

---------

Co-authored-by: pavanvora <pavanvora.cs@gmail.com>
Co-authored-by: Prashanth <prashanthsoordelu@gmail.com>
Co-authored-by: Pavan Vora <pavanvora@users.noreply.github.com>
Co-authored-by: mehulcs <mehul.becs@gmail.com>
  • Loading branch information
5 people authored Oct 2, 2024
1 parent f871795 commit 07a242d
Show file tree
Hide file tree
Showing 25 changed files with 383 additions and 60 deletions.
8 changes: 8 additions & 0 deletions .changeset/thick-foxes-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@ledgerhq/coin-cardano": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
---

Cardano fees warning + fix high fees issue
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function StepDelegationFooter({
}: StepProps) {
invariant(account, "account required");
const { errors } = status;
const canNext = !bridgePending && !errors.amount && transaction;
const canNext = !bridgePending && Object.keys(errors).length === 0 && transaction;

return (
<Box horizontal justifyContent="flex-end" flow={2} grow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { StepProps } from "../types";
import CardanoLedgerPoolIcon from "../LedgerPoolIcon";
import BigNumber from "bignumber.js";
import { useMaybeAccountUnit } from "~/renderer/hooks/useAccountUnit";
import IconExclamationCircle from "~/renderer/icons/ExclamationCircle";
import TranslatedError from "~/renderer/components/TranslatedError";

const FromToWrapper = styled.div``;
const Separator = styled.div`
Expand All @@ -27,8 +29,8 @@ function StepSummary(props: StepProps) {
const feesUnit = useMaybeAccountUnit(account);
if (!account || !transaction) return null;

const { estimatedFees } = status;

const { estimatedFees, warnings } = status;
const { feeTooHigh } = warnings;
const feesCurrency = getAccountCurrency(account);
const showDeposit = !account.cardanoResources?.delegation?.status;
const stakeKeyDeposit = account.cardanoResources?.protocolParams.stakeKeyDeposit;
Expand Down Expand Up @@ -105,7 +107,7 @@ function StepSummary(props: StepProps) {
</Text>
<Box>
<FormattedVal
color={"palette.text.shade80"}
color={feeTooHigh ? "warning" : "palette.text.shade80"}
disableRounding
unit={feesUnit}
alwaysShowValue
Expand All @@ -116,7 +118,7 @@ function StepSummary(props: StepProps) {
/>
<Box textAlign="right">
<CounterValue
color={"palette.text.shade60"}
color={feeTooHigh ? "warning" : "palette.text.shade60"}
fontSize={3}
currency={feesCurrency}
value={estimatedFees}
Expand All @@ -126,6 +128,20 @@ function StepSummary(props: StepProps) {
</Box>
</Box>
</Box>
{feeTooHigh ? (
<Box horizontal justifyContent="flex-end" alignItems="center" color="warning">
<IconExclamationCircle size={10} />
<Text
ff="Inter|Medium"
fontSize={2}
style={{
marginLeft: "5px",
}}
>
<TranslatedError error={feeTooHigh} />
</Text>
</Box>
) : null}
</FromToWrapper>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
Transaction,
TransactionStatus,
} from "@ledgerhq/live-common/families/cardano/types";
const Root = (props: {

const MemoField = (props: {
account: CardanoAccount;
transaction: Transaction;
status: TransactionStatus;
Expand All @@ -32,7 +33,4 @@ const Root = (props: {
);
};

export default {
component: Root,
fields: ["memo"],
};
export default MemoField;
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TransactionStatus,
} from "@ledgerhq/live-common/families/cardano/types";
import { track } from "~/renderer/analytics/segment";

const MemoValueField = ({
onChange,
account,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import {
CardanoAccount,
Transaction,
TransactionStatus,
} from "@ledgerhq/live-common/families/cardano/types";

import MemoField from "./MemoField";

const Root = (props: {
account: CardanoAccount;
transaction: Transaction;
status: TransactionStatus;
onChange: (t: Transaction) => void;
trackProperties?: Record<string, unknown>;
}) => {
return (
<>
<MemoField {...props} />
</>
);
};

export default {
component: Root,
fields: ["memo"],
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { StepProps } from "../types";
import BigNumber from "bignumber.js";
import Alert from "~/renderer/components/Alert";
import { useMaybeAccountUnit } from "~/renderer/hooks/useAccountUnit";
import IconExclamationCircle from "~/renderer/icons/ExclamationCircle";

const FromToWrapper = styled.div``;
const Separator = styled.div`
Expand All @@ -24,7 +25,8 @@ const Separator = styled.div`

function StepSummary(props: StepProps) {
const { account, transaction, status, error } = props;
const { estimatedFees, errors } = status;
const { estimatedFees, errors, warnings } = status;
const { feeTooHigh } = warnings;
const displayError = errors.amount?.message ? errors.amount : "";

const accountUnit = useMaybeAccountUnit(account);
Expand Down Expand Up @@ -72,7 +74,7 @@ function StepSummary(props: StepProps) {
</Text>
<Box>
<FormattedVal
color={"palette.text.shade80"}
color={feeTooHigh ? "warning" : "palette.text.shade80"}
disableRounding
unit={accountUnit}
alwaysShowValue
Expand All @@ -83,7 +85,7 @@ function StepSummary(props: StepProps) {
/>
<Box textAlign="right">
<CounterValue
color={"palette.text.shade60"}
color={feeTooHigh ? "warning" : "palette.text.shade60"}
fontSize={3}
currency={feesCurrency}
value={estimatedFees}
Expand All @@ -93,6 +95,20 @@ function StepSummary(props: StepProps) {
</Box>
</Box>
</Box>
{feeTooHigh ? (
<Box horizontal justifyContent="flex-end" alignItems="center" color="warning">
<IconExclamationCircle size={10} />
<Text
ff="Inter|Medium"
fontSize={2}
style={{
marginLeft: "5px",
}}
>
<TranslatedError error={feeTooHigh} />
</Text>
</Box>
) : null}
</FromToWrapper>
{displayError ? (
<Box grow>
Expand All @@ -114,22 +130,20 @@ export function StepSummaryFooter({
onClose,
}: StepProps) {
const { errors } = status;
const canNext = !errors.amount && !bridgePending && !errors.validators && transaction;
const canNext = Object.keys(errors).length === 0 && !bridgePending && transaction;
return (
<>
<Box horizontal justifyContent="flex-end" flow={2} grow>
<Button mr={1} secondary onClick={onClose}>
<Trans i18nKey="common.cancel" />
</Button>
<Button
id="undelegate-continue-button"
disabled={!canNext}
primary
onClick={() => transitionTo("connectDevice")}
>
<Trans i18nKey="common.continue" />
</Button>
</Box>
</>
<Box horizontal justifyContent="flex-end" flow={2} grow>
<Button mr={1} secondary onClick={onClose}>
<Trans i18nKey="common.cancel" />
</Button>
<Button
id="undelegate-continue-button"
disabled={!canNext}
primary
onClick={() => transitionTo("connectDevice")}
>
<Trans i18nKey="common.continue" />
</Button>
</Box>
);
}
12 changes: 12 additions & 0 deletions apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6084,6 +6084,18 @@
"CardanoStakeKeyDepositError": {
"title": "Ensure that you have {{depositAmount}} ADA available for the deposit"
},
"CardanoFeeHigh": {
"title": "Abnormally high network fees.",
"description": "Network fees unusually high please double check your transaction."
},
"CardanoFeeTooHigh": {
"title": "Abnormally high network fees.",
"description": "ADA transactions are temporarily unavailable. Please resync your account and try again or contact Support if you need assistance."
},
"CardanoInvalidProtoParams": {
"title": "Cardano invalid protocol parameters",
"description": "ADA transactions are temporarily unavailable. Please resync your account and try again or contact Support if you need assistance."
},
"StacksMemoTooLong": {
"title": "Memo length is too long"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import { StackNavigatorProps } from "~/components/RootNavigator/types/helpers";
import { CardanoDelegationFlowParamList } from "./types";
import TranslatedError from "~/components/TranslatedError";
import { useAccountUnit } from "~/hooks/useAccountUnit";
import GenericErrorBottomModal from "~/components/GenericErrorBottomModal";
import RetryButton from "~/components/RetryButton";
import CancelButton from "~/components/CancelButton";

type Props = StackNavigatorProps<
CardanoDelegationFlowParamList,
Expand Down Expand Up @@ -100,6 +103,21 @@ export default function DelegationSummary({ navigation, route }: Props) {
return { account, transaction: tx };
});

const [bridgeErr, setBridgeErr] = useState(bridgeError);
useEffect(() => setBridgeErr(bridgeError), [bridgeError]);

const onBridgeErrorCancel = useCallback(() => {
setBridgeErr(null);
const parent = navigation.getParent();
if (parent) parent.goBack();
}, [navigation]);
const onBridgeErrorRetry = useCallback(() => {
setBridgeErr(null);
if (!transaction) return;
const bridge = getAccountBridge(account, parentAccount);
setTransaction(bridge.updateTransaction(transaction, {}));
}, [setTransaction, account, parentAccount, transaction]);

invariant(transaction, "transaction must be defined");
invariant(transaction.family === "cardano", "transaction cardano");

Expand Down Expand Up @@ -141,6 +159,9 @@ export default function DelegationSummary({ navigation, route }: Props) {
const displayError = useMemo(() => {
return status.errors.amount ? status.errors.amount : "";
}, [status]);
const displayWarning = useMemo(() => {
return status.warnings.feeTooHigh ? status.warnings.feeTooHigh : "";
}, [status]);

return (
<SafeAreaView style={[styles.root, { backgroundColor: colors.background }]}>
Expand Down Expand Up @@ -181,14 +202,23 @@ export default function DelegationSummary({ navigation, route }: Props) {
) : (
<></>
)}
{displayWarning ? (
<Box>
<Text fontSize={13} color="orange">
<TranslatedError error={displayWarning} field="title" />
</Text>
</Box>
) : (
<></>
)}
<Button
event="SummaryContinue"
type="primary"
title={<Trans i18nKey="common.continue" />}
containerStyle={styles.continueButton}
onPress={onContinue}
disabled={
!!displayError ||
Object.keys(status.errors).length > 0 ||
bridgePending ||
!!bridgeError ||
!chosenPool ||
Expand All @@ -197,6 +227,19 @@ export default function DelegationSummary({ navigation, route }: Props) {
pending={bridgePending}
/>
</View>
<GenericErrorBottomModal
error={bridgeErr}
onClose={onBridgeErrorRetry}
footerButtons={
<>
<CancelButton containerStyle={styles.button} onPress={onBridgeErrorCancel} />
<RetryButton
containerStyle={[styles.button, styles.buttonRight]}
onPress={onBridgeErrorRetry}
/>
</>
}
/>
</SafeAreaView>
);
}
Expand Down Expand Up @@ -275,6 +318,13 @@ const styles = StyleSheet.create({
valueText: {
fontSize: 14,
},
button: {
flex: 1,
marginHorizontal: 8,
},
buttonRight: {
marginLeft: 8,
},
});

function SummaryWords({
Expand Down
Loading

0 comments on commit 07a242d

Please sign in to comment.