-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filtering providers in hooks based on FF (#6991)
* feat: filtering providers in hooks based on FF * chore: changeset * chore: lint * chore: lint
- Loading branch information
Showing
15 changed files
with
99 additions
and
52 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,6 @@ | ||
--- | ||
"@ledgerhq/types-live": patch | ||
"@ledgerhq/live-common": patch | ||
--- | ||
|
||
hooks to filter swap providers based on FF |
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
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
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
4 changes: 4 additions & 0 deletions
4
libs/ledger-live-common/src/exchange/swap/hooks/v5/useFetchCurrencyAll.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
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
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
42 changes: 42 additions & 0 deletions
42
libs/ledger-live-common/src/exchange/swap/hooks/v5/useFilteredProviders.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,42 @@ | ||
import { useState, useEffect, useCallback } from "react"; | ||
import { useFeature } from "../../../../featureFlags"; | ||
import { fetchAndMergeProviderData } from "../../../providers/swap"; | ||
|
||
export const useFilteredProviders = () => { | ||
const [providers, setProviders] = useState<string[]>([]); | ||
const [loading, setLoading] = useState(true); | ||
const [error, setError] = useState<unknown>(null); | ||
|
||
const ptxSwapMoonpayProviderFlag = useFeature("ptxSwapMoonpayProvider"); | ||
const ptxSwapExodusProviderFlag = useFeature("ptxSwapExodusProvider"); | ||
const ptxSwapThorswapProviderFlag = useFeature("ptxSwapThorswapProvider"); | ||
|
||
const fetchProviders = useCallback(async () => { | ||
try { | ||
const data = await fetchAndMergeProviderData(); | ||
|
||
let filteredProviders = Object.keys(data); | ||
if (!ptxSwapMoonpayProviderFlag?.enabled) { | ||
filteredProviders = filteredProviders.filter(provider => provider !== "moonpay"); | ||
} | ||
if (!ptxSwapExodusProviderFlag?.enabled) { | ||
filteredProviders = filteredProviders.filter(provider => provider !== "exodus"); | ||
} | ||
if (!ptxSwapThorswapProviderFlag?.enabled) { | ||
filteredProviders = filteredProviders.filter(provider => provider !== "thorswap"); | ||
} | ||
|
||
setProviders(filteredProviders); | ||
} catch (error) { | ||
setError(error); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}, [ptxSwapMoonpayProviderFlag, ptxSwapExodusProviderFlag, ptxSwapThorswapProviderFlag]); | ||
|
||
useEffect(() => { | ||
fetchProviders(); | ||
}, [fetchProviders]); | ||
|
||
return { providers, loading, error }; | ||
}; |
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
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