1
+ import { PoolInfoApi } from '@emurgo/yoroi-lib'
1
2
import { useTheme } from '@yoroi/theme'
2
3
import React from 'react'
3
4
import { defineMessages , useIntl } from 'react-intl'
@@ -8,6 +9,7 @@ import {Button, ButtonType} from '../../components/Button/Button'
8
9
import { CopyButton } from '../../components/CopyButton'
9
10
import { Text } from '../../components/Text'
10
11
import { TitledCard } from '../../components/TitledCard'
12
+ import { useSelectedNetwork } from '../../features/WalletManager/common/hooks/useSelectedNetwork'
11
13
import { useSelectedWallet } from '../../features/WalletManager/common/hooks/useSelectedWallet'
12
14
import { isEmptyString } from '../../kernel/utils'
13
15
import { YoroiWallet } from '../../yoroi-wallets/cardano/types'
@@ -16,11 +18,12 @@ import {StakePoolInfoAndHistory} from '../../yoroi-wallets/types/staking'
16
18
export const StakePoolInfo = ( { stakePoolId} : { stakePoolId : string } ) => {
17
19
const strings = useStrings ( )
18
20
const styles = useStyles ( )
21
+ const { isDark} = useTheme ( )
19
22
const { wallet} = useSelectedWallet ( )
20
23
const { stakePoolInfoAndHistory, isLoading} = useStakePoolInfoAndHistory ( { wallet, stakePoolId} )
21
24
const homepage = stakePoolInfoAndHistory ?. info ?. homepage
22
25
23
- if ( isLoading ) return < ActivityIndicator size = "large" color = " black" />
26
+ if ( isLoading ) return < ActivityIndicator size = "large" color = { isDark ? 'white' : ' black' } />
24
27
if ( ! stakePoolInfoAndHistory ?. info ) return null
25
28
26
29
return (
@@ -63,13 +66,31 @@ export const useStakePoolInfoAndHistory = (
63
66
[ string , string , string ]
64
67
> ,
65
68
) => {
69
+ const { networkManager} = useSelectedNetwork ( )
70
+ const poolInfoApi = React . useMemo (
71
+ ( ) => new PoolInfoApi ( networkManager . legacyApiBaseUrl ) ,
72
+ [ networkManager . legacyApiBaseUrl ] ,
73
+ )
66
74
const query = useQuery ( {
67
75
...options ,
68
76
queryKey : [ wallet . id , 'stakePoolInfo' , stakePoolId ] ,
69
77
queryFn : async ( ) => {
70
78
const stakePoolInfosAndHistories = await wallet . fetchPoolInfo ( { poolIds : [ stakePoolId ] } )
71
79
72
- return stakePoolInfosAndHistories [ stakePoolId ]
80
+ if ( stakePoolInfosAndHistories [ stakePoolId ] ?. info ?. name != null ) return stakePoolInfosAndHistories [ stakePoolId ]
81
+
82
+ const history = stakePoolInfosAndHistories [ stakePoolId ] ?. history
83
+ if ( history == null ) return null
84
+
85
+ const explorerPoolInfo = await poolInfoApi . getSingleExplorerPoolInfo ( stakePoolId )
86
+
87
+ return {
88
+ history,
89
+ info : {
90
+ name : explorerPoolInfo ?. name ?? '' ,
91
+ ticker : explorerPoolInfo ?. ticker ?? '' ,
92
+ } ,
93
+ }
73
94
} ,
74
95
} )
75
96
0 commit comments