|
| 1 | +import React, { useState } from 'react'; |
| 2 | +import { View, Text, TouchableOpacity, ActivityIndicator } from 'react-native'; |
| 3 | +import Icon from 'react-native-vector-icons/Feather'; |
| 4 | +import { useTranslation } from 'react-i18next'; |
| 5 | +import { useTheme } from '../../hooks'; |
| 6 | +import Authentication from '../Authentication/Authentication'; |
| 7 | + |
| 8 | +/** |
| 9 | + * RecoveryRequest — approval UI for a wallet-issued randomParams recovery |
| 10 | + * request. Matches the existing request-component pattern: |
| 11 | + * |
| 12 | + * 1. Render approve / reject buttons with explanatory copy. |
| 13 | + * 2. On approve, open the shared `Authentication` modal (biometric first, |
| 14 | + * password fallback) with `type="recovery"` to set the prompt text. |
| 15 | + * 3. Only after Authentication reports success do we call `actionStatus(true)` |
| 16 | + * back to Home.tsx, which runs the actual sk_r derivation + transit |
| 17 | + * wrap + relay post. |
| 18 | + * |
| 19 | + * Reject flows straight through to `actionStatus(false)` (no auth needed). |
| 20 | + */ |
| 21 | +const RecoveryRequest = (props: { |
| 22 | + activityStatus: boolean; |
| 23 | + actionStatus: (status: boolean) => void; |
| 24 | +}) => { |
| 25 | + const { t } = useTranslation(['home', 'common']); |
| 26 | + const { Fonts, Gutters, Layout, Colors, Common } = useTheme(); |
| 27 | + const [authenticationOpen, setAuthenticationOpen] = useState(false); |
| 28 | + |
| 29 | + const approve = () => { |
| 30 | + console.log('Approve recovery'); |
| 31 | + props.actionStatus(true); |
| 32 | + }; |
| 33 | + const openAuthentication = () => { |
| 34 | + console.log('Open Authentication (recovery)'); |
| 35 | + setAuthenticationOpen(true); |
| 36 | + }; |
| 37 | + const reject = () => { |
| 38 | + console.log('Reject recovery'); |
| 39 | + props.actionStatus(false); |
| 40 | + }; |
| 41 | + |
| 42 | + const handleAuthenticationOpen = (status: boolean) => { |
| 43 | + console.log('Recovery auth modal close, status:', status); |
| 44 | + setAuthenticationOpen(false); |
| 45 | + if (status === true) { |
| 46 | + approve(); |
| 47 | + } |
| 48 | + }; |
| 49 | + |
| 50 | + return ( |
| 51 | + <> |
| 52 | + <View |
| 53 | + style={[ |
| 54 | + Layout.fill, |
| 55 | + Layout.relative, |
| 56 | + Layout.fullWidth, |
| 57 | + Layout.justifyContentCenter, |
| 58 | + Layout.alignItemsCenter, |
| 59 | + ]} |
| 60 | + > |
| 61 | + <Icon name="refresh-cw" size={60} color={Colors.textGray400} /> |
| 62 | + <Text |
| 63 | + style={[ |
| 64 | + Fonts.textBold, |
| 65 | + Fonts.textCenter, |
| 66 | + Fonts.textRegular, |
| 67 | + Gutters.smallMargin, |
| 68 | + ]} |
| 69 | + > |
| 70 | + {t('home:recovery_request')} |
| 71 | + </Text> |
| 72 | + <Text |
| 73 | + style={[ |
| 74 | + Fonts.textSmall, |
| 75 | + Fonts.textCenter, |
| 76 | + Gutters.smallLMargin, |
| 77 | + Gutters.smallRMargin, |
| 78 | + ]} |
| 79 | + > |
| 80 | + {t('home:ssp_recovery_request')} |
| 81 | + </Text> |
| 82 | + <Text |
| 83 | + style={[ |
| 84 | + Fonts.textSmall, |
| 85 | + Fonts.textCenter, |
| 86 | + Gutters.smallLMargin, |
| 87 | + Gutters.smallRMargin, |
| 88 | + Gutters.tinyTMargin, |
| 89 | + ]} |
| 90 | + > |
| 91 | + {t('home:ssp_recovery_request_warning')} |
| 92 | + </Text> |
| 93 | + </View> |
| 94 | + <View style={[Layout.justifyContentEnd]}> |
| 95 | + <TouchableOpacity |
| 96 | + style={[ |
| 97 | + Common.button.rounded, |
| 98 | + Common.button.bluePrimary, |
| 99 | + Gutters.regularBMargin, |
| 100 | + Gutters.smallTMargin, |
| 101 | + ]} |
| 102 | + disabled={authenticationOpen || props.activityStatus} |
| 103 | + onPressIn={() => openAuthentication()} |
| 104 | + > |
| 105 | + {(authenticationOpen || props.activityStatus) && ( |
| 106 | + <ActivityIndicator |
| 107 | + size={'large'} |
| 108 | + style={[{ position: 'absolute' }]} |
| 109 | + /> |
| 110 | + )} |
| 111 | + <Text style={[Fonts.textRegular, Fonts.textWhite]}> |
| 112 | + {t('home:approve_request')} |
| 113 | + </Text> |
| 114 | + </TouchableOpacity> |
| 115 | + <TouchableOpacity |
| 116 | + disabled={authenticationOpen || props.activityStatus} |
| 117 | + onPressIn={() => reject()} |
| 118 | + > |
| 119 | + <Text |
| 120 | + style={[ |
| 121 | + Fonts.textSmall, |
| 122 | + Fonts.textBluePrimary, |
| 123 | + Gutters.regularBMargin, |
| 124 | + Fonts.textCenter, |
| 125 | + ]} |
| 126 | + > |
| 127 | + {t('home:reject')} |
| 128 | + </Text> |
| 129 | + </TouchableOpacity> |
| 130 | + </View> |
| 131 | + {authenticationOpen && ( |
| 132 | + <Authentication |
| 133 | + actionStatus={handleAuthenticationOpen} |
| 134 | + type="recovery" |
| 135 | + biomatricsAllowed={true} |
| 136 | + /> |
| 137 | + )} |
| 138 | + </> |
| 139 | + ); |
| 140 | +}; |
| 141 | + |
| 142 | +export default RecoveryRequest; |
0 commit comments