-
Notifications
You must be signed in to change notification settings - Fork 360
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feat/LIVE-9344]: Integrate feature_ptx_swap feature flag (#4843)
* feat: add feature flag * feat: add helper hook * feat: export hook from index * feat: implement use of feature flag * fix: use currency from not currency to * chore: add changeset
- Loading branch information
1 parent
c9bb258
commit 304bb46
Showing
7 changed files
with
133 additions
and
3 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,7 @@ | ||
--- | ||
"@ledgerhq/types-live": patch | ||
"ledger-live-desktop": patch | ||
"@ledgerhq/live-common": patch | ||
--- | ||
|
||
Add feature_ptx_swap_live_app feature flag and logic |
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
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
80 changes: 80 additions & 0 deletions
80
libs/ledger-live-common/src/exchange/swap/hooks/useIsSwapLiveApp.test.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,80 @@ | ||
import { renderHook } from "@testing-library/react-hooks"; | ||
import { useFeature } from "../../../featureFlags"; | ||
import { useIsSwapLiveApp } from "./useIsSwapLiveApp"; | ||
import { cryptocurrenciesById } from "@ledgerhq/cryptoassets/currencies"; | ||
|
||
// Mock dependencies. | ||
jest.mock("../../../featureFlags"); | ||
|
||
const useMockFeature = useFeature as jest.Mock; | ||
|
||
const bitcoin = cryptocurrenciesById["bitcoin"]; | ||
|
||
describe("useIsSwapLiveApp hook", () => { | ||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it("returns the enabled flag when currencyFrom is not defined", () => { | ||
useMockFeature.mockReturnValue({ enabled: true }); | ||
|
||
const { result } = renderHook(() => useIsSwapLiveApp({ currencyFrom: undefined })); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
|
||
it("returns the enabled flag when families and currencies are not defined", () => { | ||
useMockFeature.mockReturnValue({ | ||
enabled: true, | ||
params: { families: undefined, currencies: undefined }, | ||
}); | ||
|
||
const { result } = renderHook(() => useIsSwapLiveApp({ currencyFrom: bitcoin })); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
|
||
it("returns true when currencyFrom family is in families array and feature is enabled", () => { | ||
useMockFeature.mockReturnValue({ | ||
enabled: true, | ||
params: { families: ["bitcoin"], currencies: [] }, | ||
}); | ||
|
||
const { result } = renderHook(() => useIsSwapLiveApp({ currencyFrom: bitcoin })); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
|
||
it("returns true when currencyFrom is in currencies array and feature is enabled", () => { | ||
useMockFeature.mockReturnValue({ | ||
enabled: true, | ||
params: { families: [], currencies: ["bitcoin"] }, | ||
}); | ||
|
||
const { result } = renderHook(() => useIsSwapLiveApp({ currencyFrom: bitcoin })); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
|
||
it("returns false when currencyFrom family is not in families, currencyFrom is not in currencies, and feature is disabled", () => { | ||
useMockFeature.mockReturnValue({ | ||
enabled: false, | ||
params: { families: ["ethereum"], currencies: ["ethereum"] }, | ||
}); | ||
|
||
const { result } = renderHook(() => useIsSwapLiveApp({ currencyFrom: bitcoin })); | ||
|
||
expect(result.current).toBe(false); | ||
}); | ||
|
||
it("returns enabled flag if both families and currencies are empty arrays", () => { | ||
useMockFeature.mockReturnValue({ | ||
enabled: true, | ||
params: { families: [], currencies: [] }, | ||
}); | ||
|
||
const { result } = renderHook(() => useIsSwapLiveApp({ currencyFrom: bitcoin })); | ||
|
||
expect(result.current).toBe(true); | ||
}); | ||
}); |
25 changes: 25 additions & 0 deletions
25
libs/ledger-live-common/src/exchange/swap/hooks/useIsSwapLiveApp.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,25 @@ | ||
import { CryptoOrTokenCurrency } from "@ledgerhq/types-cryptoassets"; | ||
import { useFeature } from "../../../featureFlags"; | ||
import { isCryptoCurrency } from "../../../currencies"; | ||
|
||
type Props = { | ||
currencyFrom?: CryptoOrTokenCurrency; | ||
}; | ||
|
||
export function useIsSwapLiveApp({ currencyFrom }: Props) { | ||
const ptxSwapLiveApp = useFeature("ptxSwapLiveApp"); | ||
const { families, currencies } = ptxSwapLiveApp.params || {}; | ||
|
||
if (!currencyFrom || (!families && !currencies)) { | ||
return ptxSwapLiveApp.enabled; | ||
} | ||
|
||
const familyOfCurrencyFrom = isCryptoCurrency(currencyFrom) | ||
? currencyFrom.family | ||
: currencyFrom.parentCurrency.family; | ||
|
||
const familyIsEnabled = families?.length ? families.includes(familyOfCurrencyFrom) : true; | ||
const currencyIsEnabled = currencies?.length ? currencies.includes(currencyFrom.id) : true; | ||
|
||
return ptxSwapLiveApp.enabled && (familyIsEnabled || currencyIsEnabled); | ||
} |
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
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
304bb46
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.
Successfully deployed to the following URLs:
live-common-tools – ./apps/web-tools
live-common-tools-git-develop-ledgerhq.vercel.app
ledger-live-tools.vercel.app
live-common-tools-ledgerhq.vercel.app
live.ledger.tools
ledger-live.vercel.app
304bb46
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 ❌ 19 txs 💰 1 miss funds ($66.93) ⏲ 7min 26s
11 critical spec errors
Spec Bitcoin failed!
Spec Bitcoin Testnet failed!
Spec Bitcoin Gold failed!
Spec Dash failed!
Spec Digibyte failed!
Spec DogeCoin failed!
Spec Komodo failed!
Spec Litecoin failed!
Spec Qtum failed!
Spec Vertcoin failed!
Spec Viacoin failed!
❌ 19 mutation errors
Details of the 19 mutations
Spec Bitcoin (failed)
Spec Bitcoin Testnet (failed)
Spec Bitcoin Cash (7)
Spec Bitcoin Gold (failed)
Spec Dash (failed)
Spec Digibyte (failed)
Spec DogeCoin (failed)
Spec Komodo (failed)
Spec Litecoin (failed)
Spec Peercoin (5)
Spec PivX (5)
Spec Qtum (failed)
Spec Vertcoin (failed)
Spec Viacoin (failed)
Spec ZCash (5)
Spec Horizen (5)
Spec Decred (failed)
Details of the 66 uncovered mutations
Spec Bitcoin (5)
Spec Bitcoin Testnet (5)
Spec Bitcoin Gold (5)
Spec Dash (5)
Spec Digibyte (5)
Spec DogeCoin (5)
Spec Komodo (5)
Spec Litecoin (5)
Spec Peercoin (2)
Spec PivX (1)
Spec Qtum (5)
Spec Vertcoin (5)
Spec Viacoin (5)
Spec ZCash (2)
Spec Horizen (1)
Spec Decred (5)
Portfolio ($66.93) – Details of the 17 currencies
qzn85g7msq5rj2eu73dqhkez4dmwn2q6vuhpm8pdx2
PDPyJnGHyzGph4dscqcJa32RcbaKdvZp2U
DGdghn8S1uCtezNJDfmLyvMwjjKCn3WiSs
t1W1vCEVTr16Tw1J6qV9M89dUbrfRsNUwAH
znp8QE6ADYdjuvjAYJGX6GjnCZ3toxBmufn
DshyFLDNm9kX5EL6DtkATQieLH2ZCL72UUj
Performance ⏲ 7min 26s
Time spent for each spec: (total across mutations)