From bcfc907b2155ef1bf5890f1649aca6db54fad24e Mon Sep 17 00:00:00 2001 From: jorbuedo Date: Fri, 7 Jun 2024 18:58:14 +0200 Subject: [PATCH] Update pool transition api and staking --- .../.storybook/storybook.requires.js | 2 +- apps/wallet-mobile/package.json | 2 +- .../PoolTransitionModal.stories.tsx | 23 +++- .../PoolTransition/usePoolTransition.tsx | 7 +- .../Staking/StakingCenter/StakingCenter.tsx | 9 +- .../PoolTransition/usePoolTransition.json | 104 +++++++++--------- .../Staking/StakingCenter/StakingCenter.json | 16 +-- yarn.lock | 39 +++++-- 8 files changed, 122 insertions(+), 80 deletions(-) diff --git a/apps/wallet-mobile/.storybook/storybook.requires.js b/apps/wallet-mobile/.storybook/storybook.requires.js index cfe07ed9ad..9b36e55dda 100644 --- a/apps/wallet-mobile/.storybook/storybook.requires.js +++ b/apps/wallet-mobile/.storybook/storybook.requires.js @@ -199,7 +199,6 @@ const getStories = () => { "./src/features/SetupWallet/common/LogoBanner/LogoBanner.stories.tsx": require("../src/features/SetupWallet/common/LogoBanner/LogoBanner.stories.tsx"), "./src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.stories.tsx": require("../src/features/SetupWallet/common/PreparingWalletScreen/PreparingWalletScreen.stories.tsx"), "./src/features/SetupWallet/common/StepperProgress/StepperProgress.stories.tsx": require("../src/features/SetupWallet/common/StepperProgress/StepperProgress.stories.tsx"), - "./src/features/SetupWallet/common/TextInput/TextInput.stories.tsx": require("../src/features/SetupWallet/common/TextInput/TextInput.stories.tsx"), "./src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.stories.tsx": require("../src/features/SetupWallet/legacy/CheckNanoX/CheckNanoXScreen.stories.tsx"), "./src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.stories.tsx": require("../src/features/SetupWallet/legacy/ConnectNanoX/ConnectNanoXScreen.stories.tsx"), "./src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.stories.tsx": require("../src/features/SetupWallet/legacy/ImportReadOnlyWallet/ImportReadOnlyWalletScreen.stories.tsx"), @@ -216,6 +215,7 @@ const getStories = () => { "./src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.stories.tsx": require("../src/features/SetupWallet/useCases/CreateWallet/WalletDetailsScreen.stories.tsx"), "./src/features/SetupWallet/useCases/DarkThemeAnnouncement/DarkThemeAnnouncement.stories.tsx": require("../src/features/SetupWallet/useCases/DarkThemeAnnouncement/DarkThemeAnnouncement.stories.tsx"), "./src/features/SetupWallet/useCases/RestoreWallet/MnemonicInput/MnemonicInput.stories.tsx": require("../src/features/SetupWallet/useCases/RestoreWallet/MnemonicInput/MnemonicInput.stories.tsx"), + "./src/features/SetupWallet/useCases/RestoreWallet/MnemonicInput/TextInput/TextInput.stories.tsx": require("../src/features/SetupWallet/useCases/RestoreWallet/MnemonicInput/TextInput/TextInput.stories.tsx"), "./src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.stories.tsx": require("../src/features/SetupWallet/useCases/RestoreWallet/RestoreWalletDetailsScreen.stories.tsx"), "./src/features/Staking/Governance/common/Action/Action.stories.tsx": require("../src/features/Staking/Governance/common/Action/Action.stories.tsx"), "./src/features/Staking/Governance/common/LearnMoreLink/LearnMoreLink.stories.tsx": require("../src/features/Staking/Governance/common/LearnMoreLink/LearnMoreLink.stories.tsx"), diff --git a/apps/wallet-mobile/package.json b/apps/wallet-mobile/package.json index 81a20b5fbe..bb5c24399e 100644 --- a/apps/wallet-mobile/package.json +++ b/apps/wallet-mobile/package.json @@ -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", diff --git a/apps/wallet-mobile/src/legacy/Staking/PoolTransition/PoolTransitionModal.stories.tsx b/apps/wallet-mobile/src/legacy/Staking/PoolTransition/PoolTransitionModal.stories.tsx index 9433158b97..dfd2f04ff3 100644 --- a/apps/wallet-mobile/src/legacy/Staking/PoolTransition/PoolTransitionModal.stories.tsx +++ b/apps/wallet-mobile/src/legacy/Staking/PoolTransition/PoolTransitionModal.stories.tsx @@ -1,4 +1,4 @@ -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' @@ -6,22 +6,33 @@ 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, } diff --git a/apps/wallet-mobile/src/legacy/Staking/PoolTransition/usePoolTransition.tsx b/apps/wallet-mobile/src/legacy/Staking/PoolTransition/usePoolTransition.tsx index f4bb5d6a32..a6272d6486 100644 --- a/apps/wallet-mobile/src/legacy/Staking/PoolTransition/usePoolTransition.tsx +++ b/apps/wallet-mobile/src/legacy/Staking/PoolTransition/usePoolTransition.tsx @@ -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' @@ -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 : '' diff --git a/apps/wallet-mobile/src/legacy/Staking/StakingCenter/StakingCenter.tsx b/apps/wallet-mobile/src/legacy/Staking/StakingCenter/StakingCenter.tsx index 4583b5e480..dc61b9af17 100644 --- a/apps/wallet-mobile/src/legacy/Staking/StakingCenter/StakingCenter.tsx +++ b/apps/wallet-mobile/src/legacy/Staking/StakingCenter/StakingCenter.tsx @@ -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' @@ -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() @@ -82,7 +83,7 @@ export const StakingCenter = () => { handleOnMessage(event)} /> @@ -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 } diff --git a/apps/wallet-mobile/translations/messages/src/legacy/Staking/PoolTransition/usePoolTransition.json b/apps/wallet-mobile/translations/messages/src/legacy/Staking/PoolTransition/usePoolTransition.json index 4f3b4cd2b5..623930ab2a 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/Staking/PoolTransition/usePoolTransition.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/Staking/PoolTransition/usePoolTransition.json @@ -4,14 +4,14 @@ "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 } }, { @@ -19,14 +19,14 @@ "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 } }, { @@ -34,14 +34,14 @@ "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 } }, { @@ -49,14 +49,14 @@ "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 } }, { @@ -64,14 +64,14 @@ "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 } }, { @@ -79,14 +79,14 @@ "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 } }, { @@ -94,14 +94,14 @@ "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 } }, { @@ -109,14 +109,14 @@ "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 } }, { @@ -124,14 +124,14 @@ "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 } }, { @@ -139,14 +139,14 @@ "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 } }, { @@ -154,14 +154,14 @@ "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 } }, { @@ -169,14 +169,14 @@ "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 } }, { @@ -184,14 +184,14 @@ "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 } } ] \ No newline at end of file diff --git a/apps/wallet-mobile/translations/messages/src/legacy/Staking/StakingCenter/StakingCenter.json b/apps/wallet-mobile/translations/messages/src/legacy/Staking/StakingCenter/StakingCenter.json index 7340b747a2..cc6d8d7084 100644 --- a/apps/wallet-mobile/translations/messages/src/legacy/Staking/StakingCenter/StakingCenter.json +++ b/apps/wallet-mobile/translations/messages/src/legacy/Staking/StakingCenter/StakingCenter.json @@ -4,14 +4,14 @@ "defaultMessage": "!!!Invalid Pool Data", "file": "src/legacy/Staking/StakingCenter/StakingCenter.tsx", "start": { - "line": 97, + "line": 98, "column": 9, - "index": 3359 + "index": 3532 }, "end": { - "line": 100, + "line": 101, "column": 3, - "index": 3467 + "index": 3640 } }, { @@ -19,14 +19,14 @@ "defaultMessage": "!!!The data from the stake pool(s) you selected is invalid. Please try again", "file": "src/legacy/Staking/StakingCenter/StakingCenter.tsx", "start": { - "line": 101, + "line": 102, "column": 11, - "index": 3480 + "index": 3653 }, "end": { - "line": 104, + "line": 105, "column": 3, - "index": 3646 + "index": 3819 } } ] \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index f4535a9742..b89b22834a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2156,10 +2156,10 @@ bignumber.js "^9.0.1" easy-crc "1.1.0" -"@emurgo/yoroi-lib@0.15.4-alpha.7": - version "0.15.4-alpha.7" - resolved "https://registry.yarnpkg.com/@emurgo/yoroi-lib/-/yoroi-lib-0.15.4-alpha.7.tgz#a964beaee14163feb0ef50e914de744aea3aea7d" - integrity sha512-5huN9m73+XbIfQQILY4eHsT719M1HF+yOXKXxBZH2hrgNR3JfSGQtE2Ihc7ZK+4F/II39yR8XLC7lxcrq/7BLg== +"@emurgo/yoroi-lib@0.15.5-alpha.7": + version "0.15.5-alpha.7" + resolved "https://registry.yarnpkg.com/@emurgo/yoroi-lib/-/yoroi-lib-0.15.5-alpha.7.tgz#08c5f5e6b6cd611dc3134d5f1d5363aec0f49227" + integrity sha512-e5MK8rE8z2b9lJGY2NpGAzbZNpAI+KIxrou5OOi5skIlNJWGDbCpZg8HvwLOjWBYuS8pI+ii4rui5X0kTNqPjA== dependencies: "@cardano-foundation/ledgerjs-hw-app-cardano" "^6.0.0" "@emurgo/cross-csl-core" "4.4.0" @@ -21044,7 +21044,16 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.0.0, string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -21157,7 +21166,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -21185,6 +21194,13 @@ strip-ansi@^5.0.0, strip-ansi@^5.1.0, strip-ansi@^5.2.0: dependencies: ansi-regex "^4.1.0" +strip-ansi@^6.0.0, strip-ansi@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + strip-ansi@^7.0.1: version "7.1.0" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45" @@ -22797,7 +22813,7 @@ workerpool@6.2.1: resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -22833,6 +22849,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" +wrap-ansi@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" + integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== + dependencies: + ansi-styles "^4.0.0" + string-width "^4.1.0" + strip-ansi "^6.0.0" + wrappy@1: version "1.0.2" resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f"