Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jon/fix/coinrank-apy #5487

Merged
merged 2 commits into from
Mar 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions src/components/scenes/CoinRankingDetailsScene.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
const currencyCode = coinRankingCurrencyCode?.toUpperCase() ?? ''

/** Loosely Equivalent EdgeAssets for the CoinGecko coin on this scene */
const edgeAssets = React.useMemo<EdgeAsset[]>(() => {
const matchingEdgeAssets = React.useMemo<EdgeAsset[]>(() => {
if (coinRankingData == null) return []

const out = []
Expand All @@ -164,8 +164,8 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {

/** Find all wallets that can hold this asset */
const matchingWallets = React.useMemo(
() => Object.values(currencyWallets).filter(wallet => edgeAssets.some(asset => asset.pluginId === wallet.currencyInfo.pluginId)),
[edgeAssets, currencyWallets]
() => Object.values(currencyWallets).filter(wallet => matchingEdgeAssets.some(asset => asset.pluginId === wallet.currencyInfo.pluginId)),
[matchingEdgeAssets, currencyWallets]
)

/**
Expand Down Expand Up @@ -202,7 +202,7 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
}, [matchingWallets.length, coinRankingData])

// Get all stake policies we support
const [stakePolicies] = useAsyncValue<StakePolicy[]>(async () => {
const [allStakePolicies] = useAsyncValue<StakePolicy[]>(async () => {
const out = []
const pluginIds = Object.keys(currencyConfigMap)
if (currencyCode === 'FIO') {
Expand All @@ -223,9 +223,11 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
}, [currencyCode, currencyConfigMap])

const edgeStakingAssets =
stakePolicies == null
allStakePolicies == null
? []
: edgeAssets.filter(asset => filterStakePolicies(stakePolicies, { pluginId: asset.pluginId, currencyCode: currencyCode.toUpperCase() }).length > 0)
: matchingEdgeAssets.filter(
asset => filterStakePolicies(allStakePolicies, { pluginId: asset.pluginId, currencyCode: currencyCode.toUpperCase() }).length > 0
)

/** Check if all the stake plugins are loaded for this asset type */
const isStakingLoading =
Expand All @@ -238,8 +240,8 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
Object.keys(walletStakingStateMap[wallet.id].stakePolicies).length === 0
) ||
edgeStakingAssets.length === 0 ||
stakePolicies == null ||
stakePolicies.length === 0
allStakePolicies == null ||
allStakePolicies.length === 0

const imageUrlObject = React.useMemo(
() => ({
Expand Down Expand Up @@ -387,8 +389,8 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
}

const handleBuyPress = useHandler(async () => {
if (edgeAssets.length === 0) return
const forcedWalletResult = await chooseWalletListResult(edgeAssets, matchingWallets, lstrings.fiat_plugin_select_asset_to_purchase)
if (matchingEdgeAssets.length === 0) return
const forcedWalletResult = await chooseWalletListResult(matchingEdgeAssets, matchingWallets, lstrings.fiat_plugin_select_asset_to_purchase)
if (forcedWalletResult == null) return

navigation.navigate('edgeTabs', {
Expand All @@ -403,8 +405,8 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
})

const handleSellPress = useHandler(async () => {
if (edgeAssets.length === 0) return
const forcedWalletResult = await chooseWalletListResult(edgeAssets, matchingWallets, lstrings.fiat_plugin_select_asset_to_sell)
if (matchingEdgeAssets.length === 0) return
const forcedWalletResult = await chooseWalletListResult(matchingEdgeAssets, matchingWallets, lstrings.fiat_plugin_select_asset_to_sell)
if (forcedWalletResult == null) return

navigation.navigate('edgeTabs', {
Expand All @@ -419,9 +421,9 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
})

const handleSwapPress = useHandler(async () => {
if (edgeAssets.length === 0) return
if (matchingEdgeAssets.length === 0) return

const walletListResult = await chooseWalletListResult(edgeAssets, matchingWallets, lstrings.select_wallet)
const walletListResult = await chooseWalletListResult(matchingEdgeAssets, matchingWallets, lstrings.select_wallet)
if (walletListResult == null) return

const { walletId, tokenId } = walletListResult
Expand Down Expand Up @@ -493,7 +495,7 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
<EdgeText style={styles.title}>{`${currencyName} (${currencyCode})`}</EdgeText>
</EdgeAnim>
<SwipeChart assetId={coinRankingData.assetId} />
{edgeAssets.length <= 0 ? null : (
{matchingEdgeAssets.length <= 0 ? null : (
<View style={styles.buttonsContainer}>
<IconButton label={lstrings.title_buy} onPress={handleBuyPress}>
<Fontello name="buy" size={theme.rem(2)} color={theme.primaryText} />
Expand All @@ -504,7 +506,7 @@ const CoinRankingDetailsSceneComponent = (props: Props) => {
{countryCode == null || edgeStakingAssets.length === 0 ? null : (
<IconButton
label={getUkCompliantString(countryCode, 'stake_earn_button_label')}
superscriptLabel={stakingWallets.length <= 0 ? undefined : getBestApyText(stakePolicies)}
superscriptLabel={allStakePolicies == null ? undefined : getBestApyText(filterStakePolicies(allStakePolicies, { currencyCode }))}
onPress={handleStakePress}
disabled={isStakingLoading}
>
Expand Down
Loading