From 575857bb4c9cf8e9574895224ad3d888743bd017 Mon Sep 17 00:00:00 2001 From: jorbuedo Date: Wed, 5 Mar 2025 00:30:21 +0100 Subject: [PATCH] fix(wallet-mobile): Use explorer data when pool info is missing (#3856) --- .../legacy/Dashboard/DashboardNavigator.tsx | 2 +- .../src/legacy/Dashboard/StakePoolInfo.tsx | 25 +++++++++++- .../src/legacy/Dashboard/StakePoolInfos.tsx | 4 +- .../legacy/Dashboard/DashboardNavigator.json | 4 +- .../src/legacy/Dashboard/StakePoolInfo.json | 40 +++++++++---------- 5 files changed, 49 insertions(+), 26 deletions(-) diff --git a/apps/wallet-mobile/src/legacy/Dashboard/DashboardNavigator.tsx b/apps/wallet-mobile/src/legacy/Dashboard/DashboardNavigator.tsx index 48e88cd095..bafa263e4e 100644 --- a/apps/wallet-mobile/src/legacy/Dashboard/DashboardNavigator.tsx +++ b/apps/wallet-mobile/src/legacy/Dashboard/DashboardNavigator.tsx @@ -33,7 +33,7 @@ export const DashboardNavigator = () => { > Dashboard} options={{ title: meta.name, }} diff --git a/apps/wallet-mobile/src/legacy/Dashboard/StakePoolInfo.tsx b/apps/wallet-mobile/src/legacy/Dashboard/StakePoolInfo.tsx index 5c7a7424e7..a53ee5c93a 100644 --- a/apps/wallet-mobile/src/legacy/Dashboard/StakePoolInfo.tsx +++ b/apps/wallet-mobile/src/legacy/Dashboard/StakePoolInfo.tsx @@ -1,3 +1,4 @@ +import {PoolInfoApi} from '@emurgo/yoroi-lib' import {useTheme} from '@yoroi/theme' import React from 'react' import {defineMessages, useIntl} from 'react-intl' @@ -8,6 +9,7 @@ import {Button, ButtonType} from '../../components/Button/Button' import {CopyButton} from '../../components/CopyButton' import {Text} from '../../components/Text' import {TitledCard} from '../../components/TitledCard' +import {useSelectedNetwork} from '../../features/WalletManager/common/hooks/useSelectedNetwork' import {useSelectedWallet} from '../../features/WalletManager/common/hooks/useSelectedWallet' import {isEmptyString} from '../../kernel/utils' import {YoroiWallet} from '../../yoroi-wallets/cardano/types' @@ -16,11 +18,12 @@ import {StakePoolInfoAndHistory} from '../../yoroi-wallets/types/staking' export const StakePoolInfo = ({stakePoolId}: {stakePoolId: string}) => { const strings = useStrings() const styles = useStyles() + const {isDark} = useTheme() const {wallet} = useSelectedWallet() const {stakePoolInfoAndHistory, isLoading} = useStakePoolInfoAndHistory({wallet, stakePoolId}) const homepage = stakePoolInfoAndHistory?.info?.homepage - if (isLoading) return + if (isLoading) return if (!stakePoolInfoAndHistory?.info) return null return ( @@ -63,13 +66,31 @@ export const useStakePoolInfoAndHistory = ( [string, string, string] >, ) => { + const {networkManager} = useSelectedNetwork() + const poolInfoApi = React.useMemo( + () => new PoolInfoApi(networkManager.legacyApiBaseUrl), + [networkManager.legacyApiBaseUrl], + ) const query = useQuery({ ...options, queryKey: [wallet.id, 'stakePoolInfo', stakePoolId], queryFn: async () => { const stakePoolInfosAndHistories = await wallet.fetchPoolInfo({poolIds: [stakePoolId]}) - return stakePoolInfosAndHistories[stakePoolId] + if (stakePoolInfosAndHistories[stakePoolId]?.info?.name != null) return stakePoolInfosAndHistories[stakePoolId] + + const history = stakePoolInfosAndHistories[stakePoolId]?.history + if (history == null) return null + + const explorerPoolInfo = await poolInfoApi.getSingleExplorerPoolInfo(stakePoolId) + + return { + history, + info: { + name: explorerPoolInfo?.name ?? '', + ticker: explorerPoolInfo?.ticker ?? '', + }, + } }, }) diff --git a/apps/wallet-mobile/src/legacy/Dashboard/StakePoolInfos.tsx b/apps/wallet-mobile/src/legacy/Dashboard/StakePoolInfos.tsx index d0fa9468dd..dd5cde648f 100644 --- a/apps/wallet-mobile/src/legacy/Dashboard/StakePoolInfos.tsx +++ b/apps/wallet-mobile/src/legacy/Dashboard/StakePoolInfos.tsx @@ -1,3 +1,4 @@ +import {useTheme} from '@yoroi/theme' import {Balance, Wallet} from '@yoroi/types' import BigNumber from 'bignumber.js' import React from 'react' @@ -14,6 +15,7 @@ import {StakePoolInfo} from './StakePoolInfo' export const StakePoolInfos = () => { const {wallet} = useSelectedWallet() const {stakePoolIds, isLoading} = useStakePoolIds(wallet) + const {isDark} = useTheme() return stakePoolIds != null ? ( @@ -23,7 +25,7 @@ export const StakePoolInfos = () => { ) : isLoading ? ( - + ) : null } diff --git a/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/DashboardNavigator.json b/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/DashboardNavigator.json index beb6220f28..0635b791d1 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/DashboardNavigator.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/DashboardNavigator.json @@ -6,12 +6,12 @@ "start": { "line": 76, "column": 9, - "index": 2279 + "index": 2288 }, "end": { "line": 79, "column": 3, - "index": 2367 + "index": 2376 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/StakePoolInfo.json b/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/StakePoolInfo.json index f8e93184c7..3bf480f19b 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/StakePoolInfo.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/Dashboard/StakePoolInfo.json @@ -4,14 +4,14 @@ "defaultMessage": "!!!Stake pool delegated", "file": "src/legacy/Dashboard/StakePoolInfo.tsx", "start": { - "line": 105, + "line": 126, "column": 9, - "index": 3212 + "index": 4022 }, "end": { - "line": 108, + "line": 129, "column": 3, - "index": 3333 + "index": 4143 } }, { @@ -19,14 +19,14 @@ "defaultMessage": "!!!If you just delegated to a new stake pool it may take a couple of minutes for the network to process your request.", "file": "src/legacy/Dashboard/StakePoolInfo.tsx", "start": { - "line": 109, + "line": 130, "column": 11, - "index": 3346 + "index": 4156 }, "end": { - "line": 114, + "line": 135, "column": 3, - "index": 3581 + "index": 4391 } }, { @@ -34,14 +34,14 @@ "defaultMessage": "!!!Go to website", "file": "src/legacy/Dashboard/StakePoolInfo.tsx", "start": { - "line": 115, + "line": 136, "column": 26, - "index": 3609 + "index": 4419 }, "end": { - "line": 118, + "line": 139, "column": 3, - "index": 3744 + "index": 4554 } }, { @@ -49,14 +49,14 @@ "defaultMessage": "!!!Copied!", "file": "src/legacy/Dashboard/StakePoolInfo.tsx", "start": { - "line": 119, + "line": 140, "column": 10, - "index": 3756 + "index": 4566 }, "end": { - "line": 122, + "line": 143, "column": 3, - "index": 3865 + "index": 4675 } }, { @@ -64,14 +64,14 @@ "defaultMessage": "!!!Unknown pool", "file": "src/legacy/Dashboard/StakePoolInfo.tsx", "start": { - "line": 123, + "line": 144, "column": 15, - "index": 3882 + "index": 4692 }, "end": { - "line": 126, + "line": 147, "column": 3, - "index": 4001 + "index": 4811 } } ] \ No newline at end of file