Skip to content

Commit

Permalink
Clear up typechecking errors
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeAlephium committed Aug 4, 2022
1 parent e241914 commit ab1b0e7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 23 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md}\""
},
"dependencies": {
"@alephium/sdk": "0.0.12",
"@alephium/sdk": "^0.0.14",
"@craftzdog/react-native-buffer": "^6.0.4",
"@react-native-async-storage/async-storage": "~1.17.3",
"@react-navigation/native": "^6.0.10",
Expand Down
24 changes: 14 additions & 10 deletions src/screens/LoginScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,32 @@ const LoginScreen = ({ navigation, route }: ScreenProps) => {
}, [])
)

const openWallet = useCallback(async () => {
const wallet = await walletOpenAsyncUnsafe(pinCode, storedActiveEncryptedWallet.mnemonic, pbkdf2, mnemonicToSeed)
dispatch(
activeWalletChanged({
...storedActiveEncryptedWallet,
mnemonic: wallet.mnemonic
})
)
setPinCode('')
navigation.navigate('DashboardScreen')
}, [dispatch, pinCode, storedActiveEncryptedWallet, navigation])

useEffect(() => {
if (!pinFullyEntered) return

setLoading(true)

try {
dispatch(pinEntered(pinCode))
const wallet = await walletOpenAsyncUnsafe(pinCode, storedActiveEncryptedWallet.mnemonic, pbkdf2, mnemonicToSeed)
dispatch(
activeWalletChanged({
...storedActiveEncryptedWallet,
mnemonic: wallet.mnemonic
})
)
setPinCode('')
navigation.navigate('DashboardScreen')
openWallet()
} catch (e) {
setShownInstructions(errorInstructionSet)
setPinCode('')
console.error(`Could not unlock wallet ${storedActiveEncryptedWallet.name}`, e)
}
}, [dispatch, pinCode, pinFullyEntered, storedActiveEncryptedWallet, navigation])
}, [dispatch, pinCode, pinFullyEntered, openWallet, storedActiveEncryptedWallet])

return (
<Screen style={{ marginTop: 40 }}>
Expand Down
10 changes: 7 additions & 3 deletions src/screens/NewAddressScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
walletImportAsyncUnsafe
} from '@alephium/sdk'
import { StackScreenProps } from '@react-navigation/stack'
import { useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useRef, useState } from 'react'
import { ScrollView, StyleSheet, View } from 'react-native'
import RNPickerSelect from 'react-native-picker-select'
import styled from 'styled-components/native'
Expand Down Expand Up @@ -69,13 +69,17 @@ const NewAddressScreen = ({ navigation }: ScreenProps) => {
color: coloredLabel?.color
}

useEffect(() => {
const importWallet = useCallback(async () => {
const wallet = await walletImportAsyncUnsafe(mnemonicToSeed, activeWallet.mnemonic)
setSeed(wallet.seed)
generateNewAddress(wallet.seed)
}, [activeWallet])

useEffect(() => {
importWallet()

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
}, [importWallet])

const generateNewAddress = (seed?: Buffer, inGroup?: number) => {
if (!seed) return
Expand Down
4 changes: 2 additions & 2 deletions src/utils/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ along with the library. If not, see <http://www.gnu.org/licenses/>.

import rnPbkdf2 from 'react-native-fast-pbkdf2'

export const pbkdf2 = (password: string, salt: Buffer): Promise<Buffer> => {
export const pbkdf2 = async (password: string, salt: Buffer): Promise<Buffer> => {
const _salt = salt.toString('base64')
const data = rnPbkdf2.derive(password, _salt, 10000, 32, 'sha-256')
const data = await rnPbkdf2.derive(password, _salt, 10000, 32, 'sha-256')
return Buffer.from(data, 'base64')
}

Expand Down

0 comments on commit ab1b0e7

Please sign in to comment.