diff --git a/apps/wallet-mobile/.storybook/storybook.requires.js b/apps/wallet-mobile/.storybook/storybook.requires.js index ce14bcbce3..d1d11dfb54 100644 --- a/apps/wallet-mobile/.storybook/storybook.requires.js +++ b/apps/wallet-mobile/.storybook/storybook.requires.js @@ -166,7 +166,6 @@ const getStories = () => { "./src/features/Receive/common/ShareDetailsCard/ShareDetailsCard.stories.tsx": require("../src/features/Receive/common/ShareDetailsCard/ShareDetailsCard.stories.tsx"), "./src/features/Receive/common/SingleOrMultipleAddressesModal/SingleOrMultipleAddressesModal.stories.tsx": require("../src/features/Receive/common/SingleOrMultipleAddressesModal/SingleOrMultipleAddressesModal.stories.tsx"), "./src/features/Receive/common/SmallAddressCard/SmallAddressCard.stories.tsx": require("../src/features/Receive/common/SmallAddressCard/SmallAddressCard.stories.tsx"), - "./src/features/RegisterCatalyst/useCases/ConfirmVotingTx/ConfirmVotingTx.stories.tsx": require("../src/features/RegisterCatalyst/useCases/ConfirmVotingTx/ConfirmVotingTx.stories.tsx"), "./src/features/RegisterCatalyst/useCases/ShowQrCode/ShowQrCode.stories.tsx": require("../src/features/RegisterCatalyst/useCases/ShowQrCode/ShowQrCode.stories.tsx"), "./src/features/Scan/illustrations/Ilustrations.stories.tsx": require("../src/features/Scan/illustrations/Ilustrations.stories.tsx"), "./src/features/Scan/useCases/ScanCodeScreen.stories.tsx": require("../src/features/Scan/useCases/ScanCodeScreen.stories.tsx"), diff --git a/apps/wallet-mobile/src/features/RegisterCatalyst/CatalystNavigator.tsx b/apps/wallet-mobile/src/features/RegisterCatalyst/CatalystNavigator.tsx index de0fd14e4d..99c9e521d4 100644 --- a/apps/wallet-mobile/src/features/RegisterCatalyst/CatalystNavigator.tsx +++ b/apps/wallet-mobile/src/features/RegisterCatalyst/CatalystNavigator.tsx @@ -5,7 +5,6 @@ import {catalystApiMaker} from '@yoroi/staking/src' import {useTheme} from '@yoroi/theme' import React from 'react' import {useIntl} from 'react-intl' -import {StyleSheet} from 'react-native' import {Boundary} from '../../components/Boundary/Boundary' import globalMessages from '../../kernel/i18n/global-messages' @@ -18,7 +17,6 @@ import { } from '../../kernel/navigation' import {NetworkTag} from '../Settings/useCases/changeAppSettings/ChangeNetwork/NetworkTag' import {ConfirmPin} from './useCases/ConfirmPin/ConfirmPin' -import {ConfirmVotingTx} from './useCases/ConfirmVotingTx/ConfirmVotingTx' import {DisplayPin} from './useCases/DisplayPin/DisplayPin' import {DownloadCatalystAppScreen} from './useCases/DownloadCatalystAppScreen/DownloadCatalystAppScreen' import {QrCode} from './useCases/ShowQrCode/ShowQrCode' @@ -33,7 +31,6 @@ export const CatalystNavigator = () => { const {atoms, color} = useTheme() const strings = useStrings() const {track} = useMetrics() - const {styles} = useStyles() useFocusEffect( React.useCallback(() => { @@ -68,14 +65,6 @@ export const CatalystNavigator = () => { {/* STEP 3 */} - - {() => ( - - - - )} - - {/* STEP 4 */} null}} /> @@ -91,7 +80,6 @@ export const useNavigateTo = () => { return { displayPin: () => navigation.navigate('display-pin'), confirmPin: () => navigation.navigate('confirm-pin'), - confirmTx: () => navigation.navigate('confirm-tx'), qrCode: () => navigation.navigate('qr-code'), txHistory: () => resetToTxHistory(), } @@ -104,14 +92,3 @@ const useStrings = () => { title: intl.formatMessage(globalMessages.votingTitle), } } - -const useStyles = () => { - const {color} = useTheme() - const styles = StyleSheet.create({ - loadingBackground: { - backgroundColor: color.bg_color_max, - }, - }) - - return {styles} -} diff --git a/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmPin/ConfirmPin.tsx b/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmPin/ConfirmPin.tsx index a6a260c154..90c3fda793 100644 --- a/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmPin/ConfirmPin.tsx +++ b/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmPin/ConfirmPin.tsx @@ -9,8 +9,11 @@ import {Button} from '../../../../components/Button/Button' import {BACKSPACE, NumericKeyboard} from '../../../../components/NumericKeyboard' import {Space} from '../../../../components/Space/Space' import {Spacer} from '../../../../components/Spacer/Spacer' +import {useWalletNavigation} from '../../../../kernel/navigation' import {generatePrivateKeyForCatalyst} from '../../../../yoroi-wallets/cardano/catalyst' import {encryptWithPassword} from '../../../../yoroi-wallets/cardano/catalyst/catalystCipher' +import {useReviewTx} from '../../../ReviewTx/common/ReviewTxProvider' +import {useSelectedWallet} from '../../../WalletManager/common/hooks/useSelectedWallet' import {useNavigateTo} from '../../CatalystNavigator' import {Actions, Description, PinBox, Row, Stepper} from '../../common/components' import {useStrings} from '../../common/strings' @@ -19,16 +22,31 @@ export const ConfirmPin = () => { const strings = useStrings() const {isDark} = useTheme() const styles = useStyles() - const {pin, votingKeyEncryptedChanged, catalystKeyHexChanged} = useCatalyst() + const {pin, votingKeyEncryptedChanged} = useCatalyst() const navigateTo = useNavigateTo() const [currentActivePin, setCurrentActivePin] = React.useState(1) + const {wallet, meta} = useSelectedWallet() + const {onCIP36SupportChangeChanged, unsignedTxChanged, onSuccessChanged} = useReviewTx() + const {navigateToTxReview} = useWalletNavigation() const {generateVotingKeys, isLoading} = useGenerateVotingKeys({ - onSuccess: ({catalystKeyHex, votingKeyEncrypted}) => { + onSuccess: async ({catalystKeyHex, votingKeyEncrypted}) => { votingKeyEncryptedChanged(votingKeyEncrypted) - catalystKeyHexChanged(catalystKeyHex) - navigateTo.confirmTx() + let votingRegTx = await wallet.createVotingRegTx({ + catalystKeyHex, + supportsCIP36: true, + addressMode: meta.addressMode, + }) + + unsignedTxChanged(votingRegTx.votingRegTx) + onCIP36SupportChangeChanged(async (supportsCIP36: boolean) => { + votingRegTx = await wallet.createVotingRegTx({catalystKeyHex, supportsCIP36, addressMode: meta.addressMode}) + unsignedTxChanged(votingRegTx.votingRegTx) + }) + onSuccessChanged(navigateTo.qrCode) + + navigateToTxReview() }, }) diff --git a/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmVotingTx/ConfirmVotingTx.stories.tsx b/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmVotingTx/ConfirmVotingTx.stories.tsx deleted file mode 100644 index 74be329232..0000000000 --- a/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmVotingTx/ConfirmVotingTx.stories.tsx +++ /dev/null @@ -1,70 +0,0 @@ -import {action} from '@storybook/addon-actions' -import {storiesOf} from '@storybook/react-native' -import {Catalyst, CatalystProvider} from '@yoroi/staking' -import {catalystConfig} from '@yoroi/staking/src/catalyst/config' -import {WalletMeta} from '@yoroi/types/lib/typescript/wallet/meta' -import React from 'react' - -import {QueryProvider} from '../../../../../.storybook/decorators' -import {Boundary} from '../../../../components/Boundary/Boundary' -import {YoroiWallet} from '../../../../yoroi-wallets/cardano/types' -import {mocks} from '../../../../yoroi-wallets/mocks/wallet' -import {walletManagerMock, WalletManagerProviderMock} from '../../../../yoroi-wallets/mocks/WalletManagerProviderMock' -import {ConfirmVotingTx} from './ConfirmVotingTx' - -storiesOf('Catalyst ConfirmVotingTx', module) - .add('password', () => ( - - - - )) - .add('hw', () => ( - - - - )) - .add('os', () => ( - - - - )) - -const Providers = ({wallet, children, meta}: {wallet: YoroiWallet; children: React.ReactNode; meta: WalletMeta}) => { - walletManagerMock.setSelectedWalletId(wallet.id) - - const manager: Catalyst.Manager = { - config: catalystConfig, - getFundInfo: action('getFundInfo') as Catalyst.Manager['getFundInfo'], - fundStatus: action('fundStatus') as Catalyst.Manager['fundStatus'], - } - return ( - - - - - {children} - - - - - ) -} diff --git a/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmVotingTx/ConfirmVotingTx.tsx b/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmVotingTx/ConfirmVotingTx.tsx deleted file mode 100644 index 2ec8266a04..0000000000 --- a/apps/wallet-mobile/src/features/RegisterCatalyst/useCases/ConfirmVotingTx/ConfirmVotingTx.tsx +++ /dev/null @@ -1,157 +0,0 @@ -import {useCatalyst} from '@yoroi/staking' -import {useTheme} from '@yoroi/theme' -import React, {useState} from 'react' -import {ScrollView, StyleSheet, Text, View} from 'react-native' -import {SafeAreaView} from 'react-native-safe-area-context' - -import {Button} from '../../../../components/Button/Button' -import {ConfirmTxWithHwModal} from '../../../../components/ConfirmTxWithHwModal/ConfirmTxWithHwModal' -import {ConfirmTxWithOsModal} from '../../../../components/ConfirmTxWithOsModal/ConfirmTxWithOsModal' -import {ConfirmTxWithSpendingPasswordModal} from '../../../../components/ConfirmTxWithSpendingPasswordModal/ConfirmTxWithSpendingPasswordModal' -import {KeyboardAvoidingView} from '../../../../components/KeyboardAvoidingView/KeyboardAvoidingView' -import {useModal} from '../../../../components/Modal/ModalContext' -import {Space} from '../../../../components/Space/Space' -import {Spacer} from '../../../../components/Spacer/Spacer' -import {TextInput} from '../../../../components/TextInput/TextInput' -import {Instructions as HWInstructions} from '../../../../legacy/HW' -import {useVotingRegTx} from '../../../../yoroi-wallets/hooks' -import {formatTokenWithSymbol} from '../../../../yoroi-wallets/utils/format' -import {Amounts} from '../../../../yoroi-wallets/utils/utils' -import {useSelectedWallet} from '../../../WalletManager/common/hooks/useSelectedWallet' -import {useNavigateTo} from '../../CatalystNavigator' -import {Actions, Description} from '../../common/components' -import {useStrings} from '../../common/strings' - -export const ConfirmVotingTx = () => { - const [supportsCIP36, setSupportsCIP36] = useState(true) - const styles = useStyles() - const strings = useStrings() - const {openModal, closeModal} = useModal() - const {catalystKeyHex, pin} = useCatalyst() - const navigateTo = useNavigateTo() - - const onNext = () => { - navigateTo.qrCode() - } - - if (pin === null) throw new Error('pin cannot be null') - if (catalystKeyHex === null) throw new Error('catalystKeyHex cannot be null') - - const {wallet, meta} = useSelectedWallet() - const votingRegTx = useVotingRegTx({wallet, supportsCIP36, catalystKeyHex, addressMode: meta.addressMode}) - - const [useUSB, setUseUSB] = useState(false) - - const handleCIP36SupportChange = (supportsCIP36: boolean) => { - setSupportsCIP36(supportsCIP36) - } - - const onSubmit = () => { - if (meta.isHW) { - openModal( - strings.signTransaction, - onNext()} - />, - ) - return - } - - if (!meta.isHW && !meta.isEasyConfirmationEnabled) { - openModal( - strings.signTransaction, - onNext()} />, - ) - return - } - - if (!meta.isHW && meta.isEasyConfirmationEnabled) { - openModal(strings.signTransaction, onNext()} />) - return - } - } - - return ( - - - - - - {strings.confirmationTitle} - - - - {meta.isHW ? ( - <> - - - - - ) : ( - <> - - {meta.isEasyConfirmationEnabled ? strings.authOsInstructions : strings.passwordSignDescription} - - - - - )} - - - {strings.fees} - - - - - - - - -