Skip to content

Commit

Permalink
chore: pkgs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Nov 28, 2024
1 parent c42231e commit 3c108c0
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 24 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions apps/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"expo-task-manager": "~11.8.2",
"immer": "10.1.1",
"lodash": "^4.17.21",
"pbkdf2": "^3.1.2",
"process": "^0.11.10",
"react": "18.2.0",
"react-intl": "6.7.0",
Expand All @@ -94,6 +95,7 @@
"react-native-url-polyfill": "^2.0.0",
"reselect": "^4.0.0",
"rxjs": "7.8.1",
"uuid": "^11.0.3",
"zod": "3.23.8"
},
"devDependencies": {
Expand All @@ -115,8 +117,10 @@
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/react-native": "^12.7.2",
"@types/lodash": "^4.17.13",
"@types/pbkdf2": "^3.1.2",
"@types/react": "~18.2.79",
"@types/react-test-renderer": "^18.0.0",
"@types/uuid": "^10.0.0",
"babel-jest": "^29.6.3",
"dependency-cruiser": "^13.1.1",
"eslint": "^8.19.0",
Expand Down
10 changes: 8 additions & 2 deletions apps/wallet/src/InitApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ const useInitApp = () => {
}

const initInstallationId = async (storage: App.Storage) => {
const installationId = await storage.join('appSettings/').getItem('installationId', (data) => data) // LEGACY: installationId is not serialized
const installationId = await storage
.join('appSettings/')
.getItem('installationId', (data) => data) // LEGACY: installationId is not serialized
if (installationId != null) return installationId

const newInstallationId = uuid.v4()
await storage.setItem('appSettings/installationId', newInstallationId, () => newInstallationId) // LEGACY: installationId is not serialized
await storage.setItem(
'appSettings/installationId',
newInstallationId,
() => newInstallationId,
) // LEGACY: installationId is not serialized

// new installation set the storage version to the current version
// migrations happend before this, so when reading if empty returns current version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import {
TouchableOpacity,
useWindowDimensions,
View,
ViewProps,
} from 'react-native'
import {SafeAreaView} from 'react-native-safe-area-context'
import {ViewProps} from 'react-native-svg/lib/typescript/fabric/utils'

import {Button} from '../../../../components/Button/Button'
import {Icon} from '../../../../components/Icon'
Expand Down Expand Up @@ -54,11 +54,21 @@ const useSizeModal = () => {
const mediumScreenHeight = 800
const largerScreenHeight = 900
const PERCENTAGE_NAME_PASSWORD =
HEIGHT_SCREEN >= largerScreenHeight ? 58 : HEIGHT_SCREEN >= mediumScreenHeight ? 65 : 85
const PERCENTAGE_CHECKSUM = HEIGHT_SCREEN >= largerScreenHeight ? 48 : HEIGHT_SCREEN >= mediumScreenHeight ? 55 : 75
HEIGHT_SCREEN >= largerScreenHeight
? 58
: HEIGHT_SCREEN >= mediumScreenHeight
? 65
: 85
const PERCENTAGE_CHECKSUM =
HEIGHT_SCREEN >= largerScreenHeight
? 48
: HEIGHT_SCREEN >= mediumScreenHeight
? 55
: 75

const HEIGHT_MODAL_CHECKSUM = (HEIGHT_SCREEN / 100) * PERCENTAGE_CHECKSUM
const HEIGHT_MODAL_NAME_PASSWORD = (HEIGHT_SCREEN / 100) * PERCENTAGE_NAME_PASSWORD
const HEIGHT_MODAL_NAME_PASSWORD =
(HEIGHT_SCREEN / 100) * PERCENTAGE_NAME_PASSWORD

return {HEIGHT_MODAL_NAME_PASSWORD, HEIGHT_MODAL_CHECKSUM} as const
}
Expand All @@ -74,7 +84,9 @@ export const WalletDetailsScreen = () => {
const {HEIGHT_MODAL_NAME_PASSWORD, HEIGHT_MODAL_CHECKSUM} = useSizeModal()
const {openModal, closeModal} = useModal()
const {walletManager} = useWalletManager()
const walletNames = Array.from(walletManager.walletMetas.values()).map(({name}) => name)
const walletNames = Array.from(walletManager.walletMetas.values()).map(
({name}) => name,
)
const intl = useIntl()
const storage = useAsyncStorage()
const {
Expand All @@ -87,9 +99,13 @@ export const WalletDetailsScreen = () => {
accountVisual,
} = useSetupWallet()
const {plate, seed} = walletManager.checksum(publicKeyHex)
const [name, setName] = React.useState(features.prefillWalletInfo ? debugWalletInfo.WALLET_NAME : '')
const [name, setName] = React.useState(
features.prefillWalletInfo ? debugWalletInfo.WALLET_NAME : '',
)
const passwordRef = React.useRef<RNTextInput>(null)
const [password, setPassword] = React.useState(features.prefillWalletInfo ? debugWalletInfo.PASSWORD : '')
const [password, setPassword] = React.useState(
features.prefillWalletInfo ? debugWalletInfo.PASSWORD : '',
)

useFocusEffect(
React.useCallback(() => {
Expand All @@ -114,7 +130,9 @@ export const WalletDetailsScreen = () => {
const walletMeta = await walletStorage.getItem(wallet.id, parseWalletMeta)

if (!walletMeta) {
const error = new Error('WalletDetailsScreen: wallet meta is invalid, reached an invalid state.')
const error = new Error(
'WalletDetailsScreen: wallet meta is invalid, reached an invalid state.',
)
logger.error(error)
throw error
}
Expand All @@ -127,21 +145,35 @@ export const WalletDetailsScreen = () => {
InteractionManager.runAfterInteractions(() => {
return error instanceof Api.Errors.Network
? showErrorDialog(errorMessages.networkError, intl)
: showErrorDialog(errorMessages.generalError, intl, {message: error.message})
: showErrorDialog(errorMessages.generalError, intl, {
message: error.message,
})
})
},
})

const passwordErrorText =
passwordErrors.passwordIsWeak && !isLoading
? strings.passwordStrengthRequirement({requiredPasswordLength: REQUIRED_PASSWORD_LENGTH})
? strings.passwordStrengthRequirement({
requiredPasswordLength: REQUIRED_PASSWORD_LENGTH,
})
: undefined
const passwordConfirmationErrorText =
passwordErrors.matchesConfirmation && !isLoading ? strings.repeatPasswordInputError : undefined
passwordErrors.matchesConfirmation && !isLoading
? strings.repeatPasswordInputError
: undefined

const nameErrors = validateWalletName(name, null, !isCreateWalletSuccess ? walletNames : [])
const nameErrors = validateWalletName(
name,
null,
!isCreateWalletSuccess ? walletNames : [],
)
const walletNameErrorText = getWalletNameError(
{tooLong: strings.tooLong, nameAlreadyTaken: strings.nameAlreadyTaken, mustBeFilled: strings.mustBeFilled},
{
tooLong: strings.tooLong,
nameAlreadyTaken: strings.nameAlreadyTaken,
mustBeFilled: strings.mustBeFilled,
},
nameErrors,
)

Expand All @@ -156,7 +188,15 @@ export const WalletDetailsScreen = () => {
addressMode,
accountVisual,
})
}, [accountVisual, createWallet, mnemonic, name, password, track, walletImplementation])
}, [
accountVisual,
createWallet,
mnemonic,
name,
password,
track,
walletImplementation,
])

const showModalTipsPassword = React.useCallback(() => {
openModal(
Expand All @@ -166,12 +206,18 @@ export const WalletDetailsScreen = () => {
<View style={styles.modalContent}>
<CardAboutPhrase
title={strings.walletNameModalCardTitle}
linesOfText={[strings.walletNameModalCardFirstItem, strings.walletNameModalCardSecondItem]}
linesOfText={[
strings.walletNameModalCardFirstItem,
strings.walletNameModalCardSecondItem,
]}
/>

<CardAboutPhrase
title={strings.walletPasswordModalCardTitle}
linesOfText={[strings.walletPasswordModalCardFirstItem, strings.walletPasswordModalCardSecondItem]}
linesOfText={[
strings.walletPasswordModalCardFirstItem,
strings.walletPasswordModalCardSecondItem,
]}
/>
</View>
</ScrollView>
Expand Down Expand Up @@ -250,7 +296,10 @@ export const WalletDetailsScreen = () => {

return (
<KeyboardAvoidingView style={styles.root}>
<SafeAreaView edges={['left', 'right', 'bottom']} style={styles.safeAreaView}>
<SafeAreaView
edges={['left', 'right', 'bottom']}
style={styles.safeAreaView}
>
<StepperProgress
style={styles.steps}
currentStep={4}
Expand All @@ -264,14 +313,21 @@ export const WalletDetailsScreen = () => {
<Info onPress={showModalTipsPassword} />
</View>

<ScrollView style={styles.scroll} contentContainerStyle={styles.content}>
<ScrollView
style={styles.scroll}
contentContainerStyle={styles.content}
>
<TextInput
enablesReturnKeyAutomatically
autoFocus={!showRestoreWalletInfoModal}
label={strings.walletDetailsNameInput}
value={name}
onChangeText={(walletName: string) => setName(walletName)}
errorText={!isEmptyString(walletNameErrorText) && !isLoading ? walletNameErrorText : undefined}
errorText={
!isEmptyString(walletNameErrorText) && !isLoading
? walletNameErrorText
: undefined
}
errorDelay={0}
returnKeyType="next"
onSubmitEditing={() => passwordRef.current?.focus()}
Expand Down Expand Up @@ -313,7 +369,11 @@ export const WalletDetailsScreen = () => {
/>

<View style={styles.checksum}>
<Icon.WalletAvatar image={new Blockies({seed}).asBase64()} style={styles.walletChecksum} size={24} />
<Icon.WalletAvatar
image={new Blockies({seed}).asBase64()}
style={styles.walletChecksum}
size={24}
/>

<Space width="sm" />

Expand All @@ -329,7 +389,11 @@ export const WalletDetailsScreen = () => {
<Button
title={strings.next}
onPress={() => handleCreateWallet()}
disabled={isLoading || Object.keys(passwordErrors).length > 0 || Object.keys(nameErrors).length > 0}
disabled={
isLoading ||
Object.keys(passwordErrors).length > 0 ||
Object.keys(nameErrors).length > 0
}
testID="walletFormContinueButton"
/>
</Actions>
Expand All @@ -342,7 +406,10 @@ const Info = ({onPress}: {onPress: () => void}) => {
const {color, isDark} = useTheme()
return (
<TouchableOpacity onPress={onPress}>
<InfoIcon size={24} color={isDark ? color.white_static : color.black_static} />
<InfoIcon
size={24}
color={isDark ? color.white_static : color.black_static}
/>
</TouchableOpacity>
)
}
Expand Down
1 change: 1 addition & 0 deletions apps/wallet/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": "@react-native/typescript-config/tsconfig.json",
"include": [
"./.d.ts",
"./src"
]
}
17 changes: 17 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4261,6 +4261,13 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.2.tgz#5950e50960793055845e956c427fc2b0d70c5239"
integrity sha512-dISoDXWWQwUquiKsyZ4Ng+HX2KsPL7LyHKHQwgGFEA3IaKac4Obd+h2a/a6waisAoepJlBcx9paWqjA8/HVjCw==

"@types/pbkdf2@^3.1.2":
version "3.1.2"
resolved "https://registry.yarnpkg.com/@types/pbkdf2/-/pbkdf2-3.1.2.tgz#2dc43808e9985a2c69ff02e2d2027bd4fe33e8dc"
integrity sha512-uRwJqmiXmh9++aSu1VNEn3iIxWOhd8AHXNSdlaLfdAAdSTY9jYVeGWnzejM3dvrkbqE3/hyQkQQ29IFATEGlew==
dependencies:
"@types/node" "*"

"@types/prettier@^2.1.5":
version "2.7.3"
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.3.tgz#3e51a17e291d01d17d3fc61422015a933af7a08f"
Expand Down Expand Up @@ -4309,6 +4316,11 @@
resolved "https://registry.yarnpkg.com/@types/tinycolor2/-/tinycolor2-1.4.6.tgz#670cbc0caf4e58dd61d1e3a6f26386e473087f06"
integrity sha512-iEN8J0BoMnsWBqjVbWH/c0G0Hh7O21lpR2/+PrvAVgWdzL7eexIFm4JN/Wn10PTcmNdtS6U67r499mlWMXOxNw==

"@types/uuid@^10.0.0":
version "10.0.0"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-10.0.0.tgz#e9c07fe50da0f53dc24970cca94d619ff03f6f6d"
integrity sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==

"@types/yargs-parser@*":
version "21.0.3"
resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.3.tgz#815e30b786d2e8f0dcd85fd5bcf5e1a04d008f15"
Expand Down Expand Up @@ -16150,6 +16162,11 @@ utils-merge@1.0.1:
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
integrity sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==

uuid@^11.0.3:
version "11.0.3"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.0.3.tgz#248451cac9d1a4a4128033e765d137e2b2c49a3d"
integrity sha512-d0z310fCWv5dJwnX1Y/MncBAqGMKEzlBb1AOf7z9K8ALnd0utBX/msg/fA0+sbyN1ihbMsLhrBlnl1ak7Wa0rg==

uuid@^3.0.1, uuid@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
Expand Down

0 comments on commit 3c108c0

Please sign in to comment.