Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jorbuedo committed May 7, 2024
1 parent 2ea8933 commit 715caa9
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 78 deletions.
1 change: 1 addition & 0 deletions apps/wallet-mobile/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = (api) => {

const presets = ['module:@react-native/babel-preset']
const plugins = [
['@babel/plugin-transform-private-methods', {loose: true}],
[
// Used by @yoroi/dapp-connector to create injectable JS code
'babel-plugin-show-source',
Expand Down
4 changes: 3 additions & 1 deletion apps/wallet-mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
"<rootDir>/jestSetup.ts"
],
"transformIgnorePatterns": [
"node_modules/(?!(jest-)?(@react-native|react-native|react-native-iphone-x-helper|react-native-color-picker|react-native-reanimated|react-native-linear-gradient)/)"
"node_modules/(?!(jest-)?(@react-native|react-native|react-native-iphone-x-helper|react-native-color-picker|react-native-reanimated|react-native-linear-gradient|react-native-mmkv)/)",
"node_modules/(?!@testing-library/react-native)/"
]
},
"dependencies": {
Expand Down Expand Up @@ -146,6 +147,7 @@
"es6-symbol": "3.1.3",
"expo": "~50.0.11",
"expo-barcode-scanner": "~12.9.3",
"expo-blur": "12.9.2",
"expo-camera": "~14.0.5",
"expo-device": "~5.9.3",
"expo-status-bar": "~1.11.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const PrivacyPolicy = ({languageCode}: {languageCode: LanguageCode}) => {
<View>
<Spacer height={16} />

{/* @ts-expect-error old react */}
<Markdown style={styles}>{privacyPolicy}</Markdown>
</View>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const TermsOfService = ({languageCode}: {languageCode: LanguageCode}) =>
<View>
<Spacer height={16} />

{/* @ts-expect-error old react */}
<Markdown style={styles}>{tos}</Markdown>
</View>
) : (
Expand Down
10 changes: 4 additions & 6 deletions apps/wallet-mobile/src/components/Icon/Info.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import * as React from 'react'
import {ImageStyle} from 'react-native'
import Svg, {Path} from 'react-native-svg'
import Svg, {Path, SvgProps} from 'react-native-svg'

type Props = {
size?: number
color?: string
style?: ImageStyle
}
} & SvgProps

export const Info = ({size = 40, color = 'black', style = {}}: Props) => {
export const Info = ({size = 40, color = 'black', ...props}: Props) => {
return (
<Svg width={size} height={size} {...style} viewBox="-2 -2 25 25">
<Svg {...props} width={size} height={size} viewBox="-2 -2 25 25">
<Path
d="M12 7C11.4477 7 11 7.44771 11 8C11 8.55229 11.4477 9 12 9H12.01C12.5623 9 13.01 8.55229 13.01 8C13.01 7.44771 12.5623 7 12.01 7H12Z"
fill={color}
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet-mobile/src/components/Modal/ModalContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const ModalProvider = ({
const navigation = useNavigation()
const actions = React.useRef<ModalActions>({
closeModal: () => {
const lastRouteName = navigation.getState().routes.slice(-1)[0].name
const lastRouteName = navigation.getState()?.routes.slice(-1)[0].name
if (lastRouteName === 'modal') {
dispatch({type: 'close'})
navigation.goBack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const OpenOrders = () => {
// https://github.com/Emurgo/yoroi/pull/2913
const currentState = navigation.getState()
const previousState = navigationRef.current
if (currentState === previousState) return
if (!currentState || currentState === previousState) return
track.swapConfirmedPageViewed({swap_tab: 'Open Orders'})
navigationRef.current = currentState
}, [track, navigation])
Expand Down
32 changes: 24 additions & 8 deletions apps/wallet-mobile/src/utils/navigation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import {NavigationProp, NavigationState, useNavigation, useNavigationState} from '@react-navigation/native'
import {
NavigationProp,
NavigationState,
ParamListBase,
useNavigation,
useNavigationState,
} from '@react-navigation/native'
import {useEffect, useState} from 'react'
import {InteractionManager} from 'react-native'

Expand All @@ -14,7 +20,11 @@ function useKeepRoutesInHistory(routesToKeep: string[]) {
if (currentRouteId !== initialRouteId) {
return
}
const {routes} = navigation.getState()

const state = navigation.getState()
if (!state) return

const {routes} = state
const currentRouteNames = routes.map((r) => r.name)

if (compareArrays(currentRouteNames, routesToKeep)) {
Expand All @@ -29,7 +39,9 @@ function useKeepRoutesInHistory(routesToKeep: string[]) {
routes: newRoutes.map((r) => ({...r, state: undefined})),
routeNames: newRoutes.map((r) => r.name),
}
navigation.reset(newState)
// Type 'string[]' is not assignable to type '(keyof RootParamList)[]'
// eslint-disable-next-line @typescript-eslint/no-explicit-any
navigation.reset(newState as any)
})

return () => task.cancel()
Expand All @@ -46,7 +58,7 @@ export const useIsRouteActive = () => {
export function useOverridePreviousRoute<RouteName extends string>(previousRouteName: RouteName) {
const navigation = useNavigation()
const [initialRouteName] = useState(() => getNavigationRouteName(navigation))
const allRouteNames: string[] = navigation.getState().routes.map((route) => route.name)
const allRouteNames: string[] = navigation.getState()?.routes.map((route) => route.name) ?? []
const previousRouteIndex = allRouteNames.indexOf(previousRouteName)
const currentRouteIndex = allRouteNames.indexOf(initialRouteName)

Expand All @@ -62,14 +74,18 @@ export function useOverridePreviousRoute<RouteName extends string>(previousRoute

useKeepRoutesInHistory(newRoutes)
}
// https://github.com/react-navigation/react-navigation/issues/11893
type Navigation = Omit<NavigationProp<ParamListBase, string>, 'getState'> & {
getState(): NavigationState | undefined
}

function getNavigationRouteId(navigation: NavigationProp<ReactNavigation.RootParamList>) {
function getNavigationRouteId(navigation: Navigation) {
const state = navigation.getState()
return state.routes[state.index].key
return state?.routes[state.index].key
}

function getNavigationRouteName(navigation: NavigationProp<ReactNavigation.RootParamList>) {
function getNavigationRouteName(navigation: Navigation) {
return selectRouteName(navigation.getState())
}

const selectRouteName = (state: NavigationState) => state.routes[state.index].name
const selectRouteName = (state?: NavigationState) => state?.routes[state.index].name ?? ''
1 change: 1 addition & 0 deletions packages/dapp-connector/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [['@babel/plugin-transform-private-methods', {loose: true}]],
}
35 changes: 21 additions & 14 deletions packages/dapp-connector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@
},
"prettier": {
"bracketSpacing": false,
"printWidth": 120,
"quoteProps": "consistent",
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all",
"useTabs": false,
"printWidth": 120
"useTabs": false
},
"eslintConfig": {
"extends": [
Expand Down Expand Up @@ -108,18 +108,29 @@
],
"jest": {
"collectCoverage": true,
"coveragePathIgnorePatterns": [
"connector.js",
"manager.mocks.ts"
],
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.d.ts"
],
"coveragePathIgnorePatterns": [
"connector.js",
"manager.mocks.ts"
],
"coverageReporters": [
"text-summary",
"html"
],
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"moduleNameMapper": {
"^react-native$": "<rootDir>/node_modules/react-native"
},
"modulePathIgnorePatterns": [
"<rootDir>/example/node_modules",
"<rootDir>/lib/"
Expand All @@ -128,14 +139,10 @@
"setupFiles": [
"<rootDir>/jest.setup.js"
],
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
}
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!react-native-mmkv)/",
"<rootDir>/node_modules/(?!@testing-library/react-native)/"
]
},
"dependencies": {
"axios": "^1.5.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/portfolio/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
};
plugins: [['@babel/plugin-transform-private-methods', {loose: true}]],
}
13 changes: 8 additions & 5 deletions packages/portfolio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,20 @@
"statements": 100
}
},
"moduleNameMapper": {
"^react-native$": "<rootDir>/node_modules/react-native"
},
"modulePathIgnorePatterns": [
"<rootDir>/example/node_modules",
"<rootDir>/lib/"
],
"preset": "react-native",
"setupFiles": [
"<rootDir>/jest.setup.js"
],
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!react-native-mmkv)/",
"<rootDir>/node_modules/(?!@testing-library/react-native)/"
]
},
"dependencies": {
Expand Down Expand Up @@ -217,9 +224,5 @@
"preset": "angular"
}
}
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!react-native-mmkv)/",
"<rootDir>/node_modules/(?!@testing-library/react-native)/"
]
}
}
1 change: 1 addition & 0 deletions packages/theme/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [['@babel/plugin-transform-private-methods', {loose: true}]],
}
13 changes: 8 additions & 5 deletions packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,20 @@
"statements": 100
}
},
"moduleNameMapper": {
"^react-native$": "<rootDir>/node_modules/react-native"
},
"modulePathIgnorePatterns": [
"<rootDir>/example/node_modules",
"<rootDir>/lib/"
],
"preset": "react-native",
"setupFiles": [
"<rootDir>/jest.setup.js"
],
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!react-native-mmkv)/",
"<rootDir>/node_modules/(?!@testing-library/react-native)/"
]
},
"devDependencies": {
Expand Down Expand Up @@ -206,9 +213,5 @@
"preset": "angular"
}
}
},
"transformIgnorePatterns": [
"<rootDir>/node_modules/(?!react-native-mmkv)/",
"<rootDir>/node_modules/(?!@testing-library/react-native)/"
]
}
}

0 comments on commit 715caa9

Please sign in to comment.