From 02fd6c362fda20430f7b48ba83f9cba24b9802be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Couto?= Date: Fri, 20 Dec 2024 10:27:58 +0000 Subject: [PATCH] fix(LIVE-14956): Set a default 0 value for swap transactions (#8710) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### ✅ Checklist - [x] `npx changeset` was attached. - [x] **Covered by automatic tests.** - [ ] **Impact of the changes:** - ... ### 📝 Description Allow ledger-live to define an amount to swap. (Set to 0) ### ❓ Context - https://ledgerhq.atlassian.net/browse/LIVE-14956 --- ### 🧐 Checklist for the PR Reviewers - **The code aligns with the requirements** described in the linked JIRA or GitHub issue. - **The PR description clearly documents the changes** made and explains any technical trade-offs or design decisions. - **There are no undocumented trade-offs**, technical debt, or maintainability issues. - **The PR has been tested** thoroughly, and any potential edge cases have been considered and handled. - **Any new dependencies** have been justified and documented. - **Performance** considerations have been taken into account. (changes have been profiled or benchmarked if necessary) --- .changeset/moody-oranges-reply.md | 5 +++++ .../renderer/components/BalanceInfos/index.tsx | 1 + .../ContextMenu/AccountContextMenu.tsx | 1 + .../screens/account/AccountHeaderActions.tsx | 1 + .../screens/asset/AssetBalanceSummaryHeader.tsx | 1 + .../exchange/Swap2/Form/SwapWebViewDemo3.tsx | 17 +++++++++++++++-- .../screens/market/hooks/useMarketActions.ts | 1 + 7 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 .changeset/moody-oranges-reply.md diff --git a/.changeset/moody-oranges-reply.md b/.changeset/moody-oranges-reply.md new file mode 100644 index 000000000000..96bdbba4304c --- /dev/null +++ b/.changeset/moody-oranges-reply.md @@ -0,0 +1,5 @@ +--- +"ledger-live-desktop": minor +--- + +Set default value for swap exchanges diff --git a/apps/ledger-live-desktop/src/renderer/components/BalanceInfos/index.tsx b/apps/ledger-live-desktop/src/renderer/components/BalanceInfos/index.tsx index 70d95f055136..e36ba8bf3300 100644 --- a/apps/ledger-live-desktop/src/renderer/components/BalanceInfos/index.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/BalanceInfos/index.tsx @@ -168,6 +168,7 @@ export default function BalanceInfos({ state: { from: history.location.pathname, defaultAccount, + defaultAmountFrom: "0", defaultParentAccount: parentAccount, }, }); diff --git a/apps/ledger-live-desktop/src/renderer/components/ContextMenu/AccountContextMenu.tsx b/apps/ledger-live-desktop/src/renderer/components/ContextMenu/AccountContextMenu.tsx index 416cad1660f5..55974056750a 100644 --- a/apps/ledger-live-desktop/src/renderer/components/ContextMenu/AccountContextMenu.tsx +++ b/apps/ledger-live-desktop/src/renderer/components/ContextMenu/AccountContextMenu.tsx @@ -120,6 +120,7 @@ export default function AccountContextMenu({ state: { defaultCurrency: currency, defaultAccount: account, + defaultAmountFrom: "0", defaultParentAccount: parentAccount, from: history.location.pathname, }, diff --git a/apps/ledger-live-desktop/src/renderer/screens/account/AccountHeaderActions.tsx b/apps/ledger-live-desktop/src/renderer/screens/account/AccountHeaderActions.tsx index 02005b16748f..8be8d22096a2 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/account/AccountHeaderActions.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/account/AccountHeaderActions.tsx @@ -257,6 +257,7 @@ const AccountHeaderActions = ({ account, parentAccount, openModal }: Props) => { defaultCurrency: currency, defaultAccount: account, defaultParentAccount: parentAccount, + defaultAmountFrom: "0", from: history.location.pathname, }, }); diff --git a/apps/ledger-live-desktop/src/renderer/screens/asset/AssetBalanceSummaryHeader.tsx b/apps/ledger-live-desktop/src/renderer/screens/asset/AssetBalanceSummaryHeader.tsx index e135745681fa..012a641c17a2 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/asset/AssetBalanceSummaryHeader.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/asset/AssetBalanceSummaryHeader.tsx @@ -122,6 +122,7 @@ export default function AssetBalanceSummaryHeader({ defaultAccount: account, defaultParentAccount: parentAccount, defaultCurrency: currency, + defaultAmountFrom: "0", from: history.location.pathname, }, }); diff --git a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/SwapWebViewDemo3.tsx b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/SwapWebViewDemo3.tsx index d013ae215452..471471beabd9 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/SwapWebViewDemo3.tsx +++ b/apps/ledger-live-desktop/src/renderer/screens/exchange/Swap2/Form/SwapWebViewDemo3.tsx @@ -127,6 +127,7 @@ const SwapWebView = ({ manifest, liveAppUnavailable }: SwapWebProps) => { const { state } = useLocation<{ defaultAccount?: AccountLike; defaultParentAccount?: Account; + defaultAmountFrom?: string; from?: string; }>(); const { networkStatus } = useNetworkStatus(); @@ -402,11 +403,23 @@ const SwapWebView = ({ manifest, liveAppUnavailable }: SwapWebProps) => { state?.defaultAccount, state?.defaultParentAccount, ).id, + amountFrom: state?.defaultAmountFrom || "", + } + : {}), + ...(state?.from + ? { + fromPath: simplifyFromPath(state?.from), } : {}), - ...(state?.from ? { fromPath: simplifyFromPath(state?.from) } : {}), }).toString(), - [isOffline, state?.defaultAccount, state?.defaultParentAccount, state?.from, walletState], + [ + isOffline, + state?.defaultAccount, + state?.defaultParentAccount, + state?.defaultAmountFrom, + state?.from, + walletState, + ], ); const onSwapWebviewError = (error?: SwapLiveError) => { diff --git a/apps/ledger-live-desktop/src/renderer/screens/market/hooks/useMarketActions.ts b/apps/ledger-live-desktop/src/renderer/screens/market/hooks/useMarketActions.ts index a453ab1bccd5..502e8b1f1be3 100644 --- a/apps/ledger-live-desktop/src/renderer/screens/market/hooks/useMarketActions.ts +++ b/apps/ledger-live-desktop/src/renderer/screens/market/hooks/useMarketActions.ts @@ -100,6 +100,7 @@ export const useMarketActions = ({ currency, page, currenciesAll }: MarketAction state: { defaultCurrency: internalCurrency, defaultAccount, + defaultAmountFrom: "0", defaultParentAccount: "parentId" in defaultAccount && defaultAccount.parentId ? flattenedAccounts.find(a => a.id === defaultAccount.parentId)