Skip to content

Commit 7ee3b68

Browse files
committed
Merge branch 'stable/4.24.0' into 'master'
Stable 4.24.0 See merge request minds/mobile-native!1770
2 parents 48d0083 + 5e0b40d commit 7ee3b68

File tree

382 files changed

+10045
-7727
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

382 files changed

+10045
-7727
lines changed

.env.review

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
ENV=review
2+
CODEPUSH_KEY_ANDROID=SkyqwsFZDiT0ae_fRTqSE0TBPoAFBkM3IHh07
3+
CODEPUSH_KEY_IOS=WVafjCYZztL9aDlEwLSpiFCjzuGlMZ5oKCi1c

App.tsx

+32-17
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
YellowBox,
1818
} from 'react-native';
1919
import { Provider, observer } from 'mobx-react';
20+
import codePush from 'react-native-code-push';
2021

2122
import { SafeAreaProvider } from 'react-native-safe-area-context';
2223
import { NavigationContainer } from '@react-navigation/native';
@@ -39,14 +40,15 @@ import ErrorBoundary from './src/common/components/ErrorBoundary';
3940
import TosModal from './src/tos/TosModal';
4041
import ThemedStyles from './src/styles/ThemedStyles';
4142
import { StoresProvider } from './src/common/hooks/use-stores';
42-
import AppMessages from './AppMessages';
4343
import i18n from './src/common/services/i18n.service';
4444

4545
import receiveShareService from './src/common/services/receive-share.service';
4646
import AppInitManager from './AppInitManager';
4747
import { WCContextProvider } from './src/blockchain/v2/walletconnect/WalletConnectContext';
4848
import analyticsService from './src/common/services/analytics.service';
49+
import AppMessageProvider from 'AppMessageProvider';
4950
import ExperimentsProvider from 'ExperimentsProvider';
51+
import { CODE_PUSH_KEY } from '~/config/Config';
5052

5153
YellowBox.ignoreWarnings(['']);
5254

@@ -100,12 +102,24 @@ class App extends Component<Props, State> {
100102
}
101103
RefreshControl.defaultProps.tintColor = ThemedStyles.getColor('IconActive');
102104
RefreshControl.defaultProps.colors = [ThemedStyles.getColor('IconActive')];
105+
106+
// Check for codepush update and restart app immediately if necessary
107+
codePush.sync(
108+
CODE_PUSH_KEY
109+
? {
110+
installMode: codePush.InstallMode.ON_NEXT_RESTART, // install updates on app restart
111+
deploymentKey: CODE_PUSH_KEY,
112+
}
113+
: {
114+
mandatoryInstallMode: codePush.InstallMode.IMMEDIATE, // install mandatory updates immediately
115+
},
116+
);
103117
}
104118

105119
/**
106120
* On component did mount
107121
*/
108-
async componentDidMount() {
122+
componentDidMount() {
109123
// Register event listeners
110124
BackHandler.addEventListener('hardwareBackPress', this.onBackPress);
111125
Linking.addEventListener('url', this.handleOpenURL);
@@ -185,21 +199,22 @@ class App extends Component<Props, State> {
185199
onStateChange={analyticsService.onNavigatorStateChange}>
186200
<StoresProvider>
187201
<Provider key="app" {...stores}>
188-
<PortalProvider>
189-
<BottomSheetModalProvider>
190-
<ErrorBoundary
191-
message="An error occurred"
192-
containerStyle={ThemedStyles.style.centered}>
193-
<WCContextProvider>
194-
<NavigationStack
195-
key={ThemedStyles.theme + i18n.locale}
196-
showAuthNav={showAuthNav}
197-
/>
198-
</WCContextProvider>
199-
<AppMessages />
200-
</ErrorBoundary>
201-
</BottomSheetModalProvider>
202-
</PortalProvider>
202+
<AppMessageProvider key={`message_${ThemedStyles.theme}`}>
203+
<PortalProvider>
204+
<BottomSheetModalProvider>
205+
<ErrorBoundary
206+
message="An error occurred"
207+
containerStyle={ThemedStyles.style.centered}>
208+
<WCContextProvider>
209+
<NavigationStack
210+
key={ThemedStyles.theme + i18n.locale}
211+
showAuthNav={showAuthNav}
212+
/>
213+
</WCContextProvider>
214+
</ErrorBoundary>
215+
</BottomSheetModalProvider>
216+
</PortalProvider>
217+
</AppMessageProvider>
203218
</Provider>
204219
</StoresProvider>
205220
</NavigationContainer>

AppInitManager.ts

+17-9
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,23 @@ export default class AppInitManager {
7676
}
7777
} catch (err) {
7878
logService.exception('[App] Error initializing the app', err);
79-
Alert.alert(
80-
'Error',
81-
'There was an error initializing the app.\n Do you want to copy the stack trace.',
82-
[
83-
{ text: 'Yes', onPress: () => Clipboard.setString(err.stack) },
84-
{ text: 'No' },
85-
],
86-
{ cancelable: false },
87-
);
79+
if (err instanceof Error) {
80+
Alert.alert(
81+
'Error',
82+
'There was an error initializing the app.\n Do you want to copy the stack trace.',
83+
[
84+
{
85+
text: 'Yes',
86+
onPress: () => {
87+
if (err instanceof Error)
88+
Clipboard.setString(err.stack || '');
89+
},
90+
},
91+
{ text: 'No' },
92+
],
93+
{ cancelable: false },
94+
);
95+
}
8896
}
8997
}
9098
});

AppMessageProvider.tsx

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
3+
import { ThemeProvider } from 'styled-components';
4+
import {
5+
ToastContext,
6+
ToastProvider,
7+
} from '@msantang78/react-native-styled-toast';
8+
import { registerToast } from 'AppMessages';
9+
import ThemedStyles from '~/styles/ThemedStyles';
10+
11+
export default function AppMessageProvider({ children }) {
12+
const theme = React.useMemo(() => {
13+
const bg = ThemedStyles.getColor('PrimaryBorder');
14+
15+
return {
16+
space: [0, 4, 8, 12, 16, 20, 24, 32, 40, 48],
17+
colors: {
18+
text: ThemedStyles.getColor('PrimaryText'),
19+
background: bg,
20+
border: bg,
21+
muted: bg,
22+
success: '#7DBE31',
23+
error: '#FC0021',
24+
info: '#00FFFF',
25+
},
26+
};
27+
}, [ThemedStyles.theme]);
28+
return (
29+
<ThemeProvider theme={theme}>
30+
<ToastProvider position="TOP" offset={20} maxToasts={5}>
31+
<ToastContext.Consumer>
32+
{({ toast }) => {
33+
registerToast(toast);
34+
return <></>;
35+
}}
36+
</ToastContext.Consumer>
37+
{children}
38+
</ToastProvider>
39+
</ThemeProvider>
40+
);
41+
}

AppMessages.tsx

+78-136
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,92 @@
1-
import React, { useCallback } from 'react';
2-
import FlashMessage, { showMessage } from 'react-native-flash-message';
3-
import { View, StyleSheet, Platform } from 'react-native';
4-
5-
import IconIon from 'react-native-vector-icons/Ionicons';
6-
import IconAnt from 'react-native-vector-icons/AntDesign';
7-
import IconMC from 'react-native-vector-icons/MaterialCommunityIcons';
8-
import type { MessageType, Icon } from 'react-native-flash-message';
91
import ThemedStyles from './src/styles/ThemedStyles';
2+
import { ToastConfig } from '@msantang78/react-native-styled-toast/dist/Toast';
3+
4+
let toast: undefined | ((config: ToastConfig) => void);
5+
6+
export function registerToast(t) {
7+
toast = t;
8+
}
9+
10+
type MessageType = 'success' | 'info' | 'warning' | 'danger';
11+
12+
function getIcon(type: MessageType): any {
13+
switch (type) {
14+
case 'success':
15+
return {
16+
iconColor: '#59A05E',
17+
iconFamily: 'Ionicons',
18+
iconName: 'md-checkmark',
19+
};
20+
case 'warning':
21+
return {
22+
iconColor: '#D49538',
23+
iconFamily: 'Ionicons',
24+
iconName: 'ios-warning',
25+
};
26+
case 'info':
27+
return {
28+
iconColor: '#5282A7',
29+
iconFamily: 'EvilIcons',
30+
iconName: 'exclamation',
31+
};
32+
case 'danger':
33+
return {
34+
iconColor: '#CA4A34',
35+
iconFamily: 'MaterialCommunityIcons',
36+
iconName: 'alert-octagon',
37+
};
38+
}
39+
return {};
40+
}
1041

1142
/**
12-
* Show a notification message to the user
43+
* Show a notification message to the user
1344
* @param message
1445
* @param type
15-
* @param duration use 0 for permanent message
46+
* @param duration
47+
* @param subMessage
48+
* @param shouldVibrate
1649
*/
1750
export const showNotification = (
1851
message: string,
1952
type: MessageType = 'info',
2053
duration: number = 2800,
21-
position: 'top' | 'bottom' | 'center' | undefined = 'bottom',
54+
subMessage?: string,
55+
shouldVibrate = false,
56+
onPress?: () => void,
2257
) => {
23-
showMessage({
24-
floating: true,
25-
position,
26-
message,
27-
icon: type,
28-
duration,
29-
backgroundColor: '#FFFFFF',
30-
//@ts-ignore style parameter is not defined on the type
31-
style: styles.container,
32-
titleStyle: styles.title,
33-
color: '#7D7D82',
34-
type,
35-
});
36-
};
58+
if (toast) {
59+
toast({
60+
closeIconColor: ThemedStyles.getColor('SecondaryText'),
61+
message,
62+
onPress,
63+
hideAccent: true,
64+
shouldVibrate,
65+
allowFontScaling: false,
66+
// hideCloseIcon: true,
67+
duration,
68+
subMessage,
69+
...getIcon(type),
70+
closeIconSize: 18,
71+
messageProps: {
72+
fontFamily: 'Roboto-Medium',
73+
fontSize: 15,
74+
},
75+
iconSize: 24,
76+
toastStyles: {
77+
borderRadius: 4,
78+
},
79+
shadow: {
80+
shadowColor: '#000000',
81+
shadowOffset: {
82+
width: 0,
83+
height: 1,
84+
},
85+
shadowOpacity: 0.5,
86+
shadowRadius: 2,
3787

38-
/**
39-
* Icon renderer
40-
* @param icon
41-
*/
42-
const renderNotificationIcon = (icon: Icon = 'success') => {
43-
const theme = ThemedStyles.style;
44-
switch (icon) {
45-
case 'success':
46-
return (
47-
<View style={[styles.success, theme.bgSuccessBackground]}>
48-
<IconIon name="md-checkmark" color="white" size={25} />
49-
</View>
50-
);
51-
case 'info':
52-
return (
53-
<View style={[styles.info, theme.bgInfoBackground]}>
54-
<IconAnt name="exclamationcircleo" color="white" size={25} />
55-
</View>
56-
);
57-
case 'warning':
58-
return (
59-
<View style={[styles.warning, theme.bgWarningBackground]}>
60-
<IconIon name="ios-warning" color="white" size={25} />
61-
</View>
62-
);
63-
case 'danger':
64-
return (
65-
<View style={[styles.danger, theme.bgDangerBackground]}>
66-
<IconMC name="alert-octagon" color="white" size={25} />
67-
</View>
68-
);
88+
elevation: 4,
89+
},
90+
});
6991
}
70-
return null;
7192
};
72-
73-
/**
74-
* App messages component
75-
*/
76-
const AppMessages = () => {
77-
const renderNotification = useCallback(
78-
(message: any) =>
79-
message.renderCustomContent ? message.renderCustomContent() : null,
80-
[],
81-
);
82-
return (
83-
<FlashMessage
84-
//@ts-ignore renderCustomContent prop is not defined on the type
85-
renderCustomContent={renderNotification}
86-
renderFlashMessageIcon={renderNotificationIcon}
87-
/>
88-
);
89-
};
90-
91-
const styles = StyleSheet.create({
92-
info: {
93-
height: '100%',
94-
aspectRatio: 1,
95-
justifyContent: 'center',
96-
alignItems: 'center',
97-
},
98-
success: {
99-
height: '100%',
100-
aspectRatio: 1,
101-
justifyContent: 'center',
102-
alignItems: 'center',
103-
},
104-
danger: {
105-
height: '100%',
106-
aspectRatio: 1,
107-
justifyContent: 'center',
108-
alignItems: 'center',
109-
},
110-
warning: {
111-
height: '100%',
112-
aspectRatio: 1,
113-
justifyContent: 'center',
114-
alignItems: 'center',
115-
},
116-
title: {
117-
fontSize: 17,
118-
padding: 15,
119-
paddingRight: 15,
120-
marginRight: 55,
121-
alignSelf: 'center',
122-
flexWrap: 'wrap',
123-
},
124-
container: {
125-
shadowColor: 'black',
126-
shadowOpacity: Platform.select({ ios: 0.2, android: 0.3 }),
127-
shadowOffset: { width: 0, height: 5 },
128-
shadowRadius: 10,
129-
elevation: 15,
130-
alignItems: 'center',
131-
minHeight: 70,
132-
borderRadius: 0,
133-
paddingHorizontal: 0,
134-
paddingVertical: 0,
135-
marginTop: 0,
136-
marginLeft: 0,
137-
marginRight: 0,
138-
marginBottom: 0,
139-
},
140-
messageHorizontalLine: {
141-
marginLeft: -20,
142-
marginRight: -20,
143-
},
144-
messageVerticalLine: {
145-
marginTop: -10,
146-
marginBottom: -14,
147-
},
148-
});
149-
150-
export default AppMessages;

0 commit comments

Comments
 (0)