Skip to content

Commit

Permalink
fix: wallet and pkey login flows
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashshah committed Feb 19, 2024
1 parent 280cfb5 commit 2d29647
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/navigation/screens/SignInScreenAdvance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import useNotice from 'src/hooks/ui/useNotice';
import {setAuthType, setInitialSignin, setIsGuest} from 'src/redux/authSlice';

const SignInScreenAdvance = () => {
const [loading, setLoading] = useState<boolean>(false);
const [privateKey, setPrivateKey] = useState('');
const [error, setError] = useState({title: '', subtitle: ''});
const qrScannerRef = useRef<QRScanner>(null);
Expand All @@ -39,6 +40,7 @@ const SignInScreenAdvance = () => {
};

const handleLogin = async (key?: string) => {
setLoading(true);
const pkey = key || privateKey;
const provider = Web3Helper.getWeb3Provider();
const {success, wallet} = await Web3Helper.getWalletAddress(pkey, provider);
Expand Down Expand Up @@ -69,6 +71,7 @@ const SignInScreenAdvance = () => {
fromOnboarding: true,
});
}
setLoading(false);
};

return (
Expand All @@ -79,7 +82,8 @@ const SignInScreenAdvance = () => {
footerLabel="Your private key can be used by malicious apps to compromise you. [Learn about risks](https://www.coinbase.com/learn/crypto-basics/what-is-a-private-key) and [Verify our repo](https://github.com/ethereum-push-notification-service/push-mobile-app)"
footerButtons={[
{
onPress: handleLogin,
loading: loading,
onPress: () => handleLogin(),
title: 'Import',
bgColor: GLOBALS.COLORS.PINK,
fontColor: GLOBALS.COLORS.WHITE,
Expand Down Expand Up @@ -107,12 +111,11 @@ const SignInScreenAdvance = () => {
limit={64}
defaultValue={privateKey}
value={privateKey}
onChangeText={async key => {
setPrivateKey(key);
await handleLogin(key);
}}
onChangeText={txt => setPrivateKey(txt)}
title="Enter private key"
multiline={true}
textAlignVertical="center"
returnKeyType="done"
onSubmitEditing={() => handleLogin()}
/>
</View>
</OnboardingWrapper>
Expand All @@ -123,7 +126,10 @@ const SignInScreenAdvance = () => {
errorMessage="Ensure that it is a valid Eth private key QR"
title="Scan your Eth private key to link your device to the push app"
qrType={QR_TYPES.ETH_PK_SCAN}
doneFunc={(code: string) => setPrivateKey(code)}
doneFunc={async (code: string) => {
setPrivateKey(code);
await handleLogin(code);
}}
closeFunc={() => toggleQRScanner(false)}
/>
<PermissionsNotice
Expand Down
12 changes: 10 additions & 2 deletions src/navigation/screens/SignInScreenWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import useNotice from 'src/hooks/ui/useNotice';
import {setAuthType, setInitialSignin, setIsGuest} from 'src/redux/authSlice';

const SignInScreenWallet = () => {
const [loading, setLoading] = useState<boolean>(false);
const [input, setInput] = useState('');
const [error, setError] = useState({title: '', subtitle: ''});

Expand All @@ -39,6 +40,7 @@ const SignInScreenWallet = () => {
};

const handleSignin = async (code?: string) => {
setLoading(true);
const address = code || input;
try {
const {wallet} = await Web3Helper.resolveBlockchainDomainAndWallet(
Expand All @@ -60,11 +62,14 @@ const SignInScreenWallet = () => {
// @ts-ignore
navigation.navigate(GLOBALS.SCREENS.BIOMETRIC);
} catch (e) {
console.log('Errror', e);
setError({
title: 'Invalid Wallet Address or Domain',
subtitle: 'Please enter a valid erc20 wallet address or web3 domain',
});
showErrorNotice();
} finally {
setLoading(false);
}
};

Expand All @@ -74,8 +79,9 @@ const SignInScreenWallet = () => {
title="Enter your wallet address to sign in."
footerButtons={[
{
loading: loading,
title: 'Sign In',
onPress: handleSignin,
onPress: () => handleSignin(),
bgColor: GLOBALS.COLORS.PINK,
fontColor: GLOBALS.COLORS.WHITE,
},
Expand Down Expand Up @@ -103,7 +109,9 @@ const SignInScreenWallet = () => {
value={input}
onChangeText={txt => setInput(txt)}
title="Enter Wallet Address or Web3 Domain"
multiline={true}
textAlignVertical="center"
returnKeyType="done"
onSubmitEditing={() => handleSignin()}
/>
</View>
</OnboardingWrapper>
Expand Down

0 comments on commit 2d29647

Please sign in to comment.