forked from nearform/open-banking-reference-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
130 lines (112 loc) · 4.34 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import React, { Component } from 'react'
import { initialState, Provider, AppState } from './src/store'
import { Asset } from 'expo-asset'
import * as Font from 'expo-font'
import { AsyncStorage, Image, Text, YellowBox } from 'react-native'
import App from './src/app'
// Mute multiple known warnings to display on device. Those warning messages coming from React Native components and need to be fixed by RN team
YellowBox.ignoreWarnings(['Animated', 'Warning: componentWill', 'Possible Unhandled Promise'])
function cacheImages(images: any[]) {
return images.map((image: any) => {
// network only
if (typeof image === 'string' && image.startsWith('http')) {
return Image.prefetch(image)
} else {
return Asset.fromModule(image).downloadAsync()
}
})
}
type State = typeof state
const state = {
pin: null as string | null,
fontLoaded: false
}
class PolarisBank extends Component<{}, State> {
state: State = state
async componentDidMount() {
const pin = await AsyncStorage.getItem('@PolarisBank:pin')
const fonts = Font.loadAsync({
NB: require('./src/assets/fonts/FiraSans-Regular.ttf'),
'fira-sans-bold': require('./src/assets/fonts/FiraSans-SemiBold.ttf'),
'fira-sans-light': require('./src/assets/fonts/FiraSans-Light.ttf'),
'fira-sans': require('./src/assets/fonts/FiraSans-Regular.ttf'),
'fira-sans-semi-bold': require('./src/assets/fonts/FiraSans-SemiBold.ttf')
})
const images = cacheImages([
require('./src/assets/images/ic-screen1.png'),
require('./src/assets/images/ic-screen2.png'),
require('./src/assets/images/ic-screen3.png'),
require('./src/assets/avatars/avi1.png'),
require('./src/assets/avatars/avi2.png'),
require('./src/assets/avatars/avi3.png'),
require('./src/assets/avatars/avi4.png'),
require('./src/assets/avatars/avi3.png'),
require('./src/assets/logos/appicon.png'),
require('./src/assets/logos/appicon2.png'),
require('./src/assets/logos/appicon3.png'),
require('./src/assets/logos/edp.png'),
require('./src/assets/logos/naturgy.png'),
require('./src/assets/logos/vodafone.png'),
require('./src/assets/logos/amazon.png'),
require('./src/assets/logos/tap.png'),
require('./src/assets/logos/starbucks.png'),
require('./src/assets/logos/spotify.png'),
require('./src/assets/logos/abanca.png'),
require('./src/assets/logos/bbva.png'),
require('./src/assets/logos/bnm.png'),
require('./src/assets/logos/bancamarch.png'),
require('./src/assets/logos/bancopastor.png'),
require('./src/assets/logos/santander.png'),
require('./src/assets/logos/santander-red.png'),
require('./src/assets/logos/santander-big.png'),
require('./src/assets/logos/caixa.png'),
require('./src/assets/logos/deutsche.png'),
require('./src/assets/logos/ING.png'),
require('./src/assets/logos/ibercaja.png'),
require('./src/assets/logos/forgerock.png'),
require('./src/assets/logos/polaris.png'),
require('./src/assets/icons/icClothing.png'),
require('./src/assets/icons/fitness.png'),
require('./src/assets/icons/coffee.png'),
require('./src/assets/icons/icCamera.png'),
require('./src/assets/icons/ic-menu.png'),
require('./src/assets/icons/ic-menu-off.png'),
require('./src/assets/icons/ic-home.png'),
require('./src/assets/icons/ic-home-off.png'),
require('./src/assets/icons/ic-messages.png'),
require('./src/assets/icons/ic-messages-off.png')
])
await Promise.all([...images, fonts])
this.setState({ pin, fontLoaded: true })
}
render() {
return this.state.fontLoaded ? <App /> : null
}
}
interface RootState {
store?: AppState
}
export default class PolarisBankApp extends Component<{}, RootState> {
state: RootState = {}
async componentDidMount() {
let localState: AppState | undefined
try {
const stateFromStorage = await AsyncStorage.getItem('@PolarisBank:state')
if (stateFromStorage) {
localState = JSON.parse(stateFromStorage)
}
} catch (_) {}
this.setState({ store: initialState(localState) })
}
render() {
const { store } = this.state
if (!store) {
return <Text>Loading...</Text>
}
return (
<Provider initialState={store}>
<PolarisBank />
</Provider>
)
}
}