Skip to content

Commit

Permalink
Update pool transition api and staking
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed Jun 7, 2024
1 parent 950d1ce commit bcfc907
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 80 deletions.
2 changes: 1 addition & 1 deletion apps/wallet-mobile/.storybook/storybook.requires.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"@emurgo/csl-mobile-bridge": "6.0.0-alpha.9",
"@emurgo/react-native-blockies-svg": "^0.0.2",
"@emurgo/react-native-hid": "^5.15.6",
"@emurgo/yoroi-lib": "0.15.4-alpha.7",
"@emurgo/yoroi-lib": "0.15.5-alpha.7",
"@formatjs/intl-datetimeformat": "^6.7.0",
"@formatjs/intl-getcanonicallocales": "^2.1.0",
"@formatjs/intl-locale": "^3.2.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import {PoolInfo} from '@emurgo/yoroi-lib'
import {PoolTransition} from '@emurgo/yoroi-lib'
import {action} from '@storybook/addon-actions'
import {storiesOf} from '@storybook/react-native'
import * as React from 'react'
import {View} from 'react-native'

import {PoolTransitionModal} from './PoolTransitionModal'

const mock = {
const mock: PoolTransition = {
current: {
id: '',
hash: '',
saturation: '',
taxFix: '',
stake: '',
share: '',
pic: 'https://img.cexplorer.io/a/5/5/f/2/pool12eht6dqxpzqj87xuextrpufz2gxmt4reuesuw26r2utzw0kw906.png',
ticker: 'EMRG',
name: 'emurgo old',
roa: '0',
taxRate: '0.05',
} as unknown as PoolInfo,
taxRatio: '0.05',
},
suggested: {
hash: '',
saturation: '',
taxFix: '',
stake: '',
share: '',
pic: 'https://img.cexplorer.io/e/c/2/3/1/pool1dkww2vlysa8lsnuf5rca979zdsyr3zvt59hu7e420yxfunkka2z.png',
id: 'df1750df9b2df285fcfb50f4740657a18ee3af42727d410c37b86207',
name: 'emurgo new',
roa: '5.1',
ticker: 'EMRG',
taxRate: '0.02',
} as unknown as PoolInfo,
taxRatio: '0.02',
},
deadlineMilliseconds: Date.now() + 2999777000,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {useQuery} from 'react-query'

import {features} from '../../../features'
import {useSelectedWallet} from '../../../features/WalletManager/context/SelectedWalletContext'
import {getCardanoNetworkConfigById} from '../../../yoroi-wallets/cardano/networks'
import {YoroiWallet} from '../../../yoroi-wallets/cardano/types'
import {asQuantity, Quantities} from '../../../yoroi-wallets/utils'
import {useStakingInfo} from '../../Dashboard/StakePoolInfos'
Expand All @@ -26,12 +27,14 @@ const createDelegationTx = async (wallet: YoroiWallet, poolId: string) => {
return wallet.createDelegationTx(poolId, new BigNumber(amountToDelegate))
}

const poolInfoApi = new PoolInfoApi()

export const usePoolTransition = () => {
const navigation = useNavigation()
const wallet = useSelectedWallet()
const {stakingInfo, isLoading} = useStakingInfo(wallet)
const poolInfoApi = React.useMemo(
() => new PoolInfoApi(getCardanoNetworkConfigById(wallet.networkId).BACKEND.API_ROOT),
[wallet.networkId],
)

const isStaked = stakingInfo?.status === 'staked'
const currentPoolId = isStaked ? stakingInfo?.poolId : ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {useMetrics} from '../../../kernel/metrics/metricsManager'
import {StakingCenterRouteNavigation} from '../../../kernel/navigation'
import {NETWORKS} from '../../../yoroi-wallets/cardano/networks'
import {NotEnoughMoneyToSendError} from '../../../yoroi-wallets/cardano/types'
import {usePlate} from '../../../yoroi-wallets/hooks'
import {useStakingTx} from '../../Dashboard/StakePoolInfos'
import {PoolDetailScreen} from '../PoolDetails'

Expand All @@ -27,7 +28,7 @@ export const StakingCenter = () => {
const {languageCode} = useLanguage()
const wallet = useSelectedWallet()
const {track} = useMetrics()

const plate = usePlate({networkId: wallet.networkId, publicKeyHex: wallet.publicKeyHex})
useFocusEffect(
React.useCallback(() => {
track.stakingCenterPageViewed()
Expand Down Expand Up @@ -82,7 +83,7 @@ export const StakingCenter = () => {
<WebView
originWhitelist={['*']}
androidLayerType="software"
source={{uri: prepareStakingURL(languageCode)}}
source={{uri: prepareStakingURL(languageCode, plate.accountPlate.TextPart)}}
onMessage={(event) => handleOnMessage(event)}
/>
</View>
Expand All @@ -108,12 +109,14 @@ const noPoolDataDialog = defineMessages({
* Prepares WebView's target staking URI
* @param {*} poolList : Array of delegated pool hash
*/
const prepareStakingURL = (locale: string): string => {
const prepareStakingURL = (locale: string, plate: string): string => {
// source=mobile is constant and already included
let finalURL = NETWORKS.HASKELL_SHELLEY.POOL_EXPLORER

const lang = locale.slice(0, 2)
finalURL += `&lang=${lang}`

finalURL += `&bias=${plate}`

return finalURL
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,194 +4,194 @@
"defaultMessage": "!!!Upgrade your stake pool",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 105,
"line": 108,
"column": 9,
"index": 3653
"index": 3854
},
"end": {
"line": 108,
"line": 111,
"column": 3,
"index": 3751
"index": 3952
}
},
{
"id": "components.pooltransition.warning",
"defaultMessage": "!!!The current stake pool you're using will soon close. Migrate to the new EMURGO pool to sustain reward generation.",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 109,
"line": 112,
"column": 11,
"index": 3764
"index": 3965
},
"end": {
"line": 113,
"line": 116,
"column": 3,
"index": 3960
"index": 4161
}
},
{
"id": "components.pooltransition.finalWarning",
"defaultMessage": "!!!The current stake pool you're using is decommissioned and NOT generating reward anymore. Update it to continue earning",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 114,
"line": 117,
"column": 16,
"index": 3978
"index": 4179
},
"end": {
"line": 118,
"line": 121,
"column": 3,
"index": 4184
"index": 4385
}
},
{
"id": "components.pooltransition.currentPool",
"defaultMessage": "!!!Current pool",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 119,
"line": 122,
"column": 15,
"index": 4201
"index": 4402
},
"end": {
"line": 122,
"line": 125,
"column": 3,
"index": 4294
"index": 4495
}
},
{
"id": "components.pooltransition.newPool",
"defaultMessage": "!!!New pool",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 123,
"line": 126,
"column": 11,
"index": 4307
"index": 4508
},
"end": {
"line": 126,
"line": 129,
"column": 3,
"index": 4392
"index": 4593
}
},
{
"id": "components.pooltransition.estimatedRoa",
"defaultMessage": "!!!Estimated ROA",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 127,
"line": 130,
"column": 16,
"index": 4410
"index": 4611
},
"end": {
"line": 130,
"line": 133,
"column": 3,
"index": 4505
"index": 4706
}
},
{
"id": "components.pooltransition.fee",
"defaultMessage": "!!!Fee",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 131,
"line": 134,
"column": 7,
"index": 4514
"index": 4715
},
"end": {
"line": 134,
"line": 137,
"column": 3,
"index": 4590
"index": 4791
}
},
{
"id": "components.pooltransition.poolGeneratesRewards",
"defaultMessage": "!!!This pool continues to generate staking rewards",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 135,
"line": 138,
"column": 24,
"index": 4616
"index": 4817
},
"end": {
"line": 138,
"line": 141,
"column": 3,
"index": 4753
"index": 4954
}
},
{
"id": "components.pooltransition.poolNoRewards",
"defaultMessage": "!!!This pool is NOT generating staking rewards anymore",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 139,
"line": 142,
"column": 17,
"index": 4772
"index": 4973
},
"end": {
"line": 142,
"line": 145,
"column": 3,
"index": 4906
"index": 5107
}
},
{
"id": "components.pooltransition.poolWillStopRewards",
"defaultMessage": "!!!This pool will stop generating rewards in",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 143,
"line": 146,
"column": 23,
"index": 4931
"index": 5132
},
"end": {
"line": 146,
"line": 149,
"column": 3,
"index": 5061
"index": 5262
}
},
{
"id": "components.pooltransition.skipNoRewards",
"defaultMessage": "!!!Skip and stop receiving rewards",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 147,
"line": 150,
"column": 17,
"index": 5080
"index": 5281
},
"end": {
"line": 150,
"line": 153,
"column": 3,
"index": 5194
"index": 5395
}
},
{
"id": "components.pooltransition.updateKeepEarning",
"defaultMessage": "!!!Update now and keep earning",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 151,
"line": 154,
"column": 21,
"index": 5217
"index": 5418
},
"end": {
"line": 154,
"line": 157,
"column": 3,
"index": 5331
"index": 5532
}
},
{
"id": "components.pooltransition.update",
"defaultMessage": "!!!Update pool",
"file": "src/legacy/Staking/PoolTransition/usePoolTransition.tsx",
"start": {
"line": 155,
"line": 158,
"column": 10,
"index": 5343
"index": 5544
},
"end": {
"line": 158,
"line": 161,
"column": 3,
"index": 5430
"index": 5631
}
}
]
Loading

0 comments on commit bcfc907

Please sign in to comment.