Skip to content

Commit

Permalink
[Issue-941]: Fix bug related to WalletConnect feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhquang committed Aug 15, 2023
1 parent b5aaf71 commit e809398
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 43 deletions.
6 changes: 3 additions & 3 deletions src/AppNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { AddProvider } from 'screens/AddProvider';
import TransactionScreen from 'screens/Transaction/TransactionScreen';
import SendNFT from 'screens/Transaction/NFT';
import changeNavigationBarColor from 'react-native-navigation-bar-color';
import { Platform, StatusBar } from 'react-native';
import { Keyboard, Platform, StatusBar } from 'react-native';
import { useSubWalletTheme } from 'hooks/useSubWalletTheme';
import { Home } from 'screens/Home';
import { deviceWidth } from 'constants/index';
Expand Down Expand Up @@ -170,8 +170,8 @@ const AppNavigator = ({ isAppReady }: Props) => {
if (hasConfirmations && currentRoute && amount) {
if (currentRoute.name !== 'Confirmations' && amount) {
if (!['CreateAccount', 'CreatePassword', 'Login', 'UnlockModal'].includes(currentRoute.name) && amount) {
appModalContext.hideConfirmModal();
setTimeout(() => navigationRef.current?.navigate('Confirmations'), 1000);
Keyboard.dismiss();
navigationRef.current?.navigate('Confirmations');
}
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/AppNew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,23 @@ export const AppNew = () => {
<ExternalRequestContextProvider>
<QrSignerContextProvider>
<ScannerContextProvider>
<AppModalContextProvider>
<GestureHandlerRootView
style={{
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
width: '100%',
height: '100%',
zIndex: 9999,
}}>
<PortalProvider>
<GestureHandlerRootView
style={{
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
right: 0,
width: '100%',
height: '100%',
zIndex: 9999,
}}>
<PortalProvider>
<AppModalContextProvider>
<AppNavigator isAppReady={isAppReady} />
</PortalProvider>
</GestureHandlerRootView>
</AppModalContextProvider>
</AppModalContextProvider>
</PortalProvider>
</GestureHandlerRootView>
</ScannerContextProvider>
</QrSignerContextProvider>
</ExternalRequestContextProvider>
Expand Down
7 changes: 4 additions & 3 deletions src/components/Field/Password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ export const PasswordField = forwardRef((passwordFieldProps: Props, ref: React.R
</View>
</View>

<View style={{ gap: 8 }}>
<View style={{ marginTop: 8 }}>
{!!(errorMessages && errorMessages.length) &&
errorMessages.map((message, index) => <Warning key={index} isDanger message={message} />)}
errorMessages.map((message, index) => (
<Warning style={{ marginBottom: 8 }} key={index} isDanger message={message} />
))}
</View>
</>
);
Expand All @@ -119,7 +121,6 @@ function createStyle(theme: ThemeTypes, hasLabel: boolean, isValid: boolean, rea
backgroundColor: theme.colorBgSecondary,
width: '100%',
position: 'relative',
marginBottom: 8,
height: hasLabel ? 72 : 48,
},
inputLabel: {
Expand Down
9 changes: 5 additions & 4 deletions src/components/WalletConnect/ConnectionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ export const ConnectionItem = ({ session, onPress }: Props) => {
}}
leftItem={<Image src={getImageSource(currentDomain)} shape={'circle'} style={{ width: 28, height: 28 }} />}
middleItem={
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 8, justifyContent: 'space-between' }}>
<Typography.Text ellipsis size={'md'} style={{ ...FontSemiBold, color: theme.colorWhite, maxWidth: 96 }}>
<View
style={{ flexDirection: 'row', alignItems: 'center', gap: 8, justifyContent: 'space-between', flex: 1 }}>
<Typography.Text ellipsis size={'md'} style={{ ...FontSemiBold, color: theme.colorWhite, flex: 1 }}>
{dAppInfo.name}
</Typography.Text>
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 16 }}>
<Typography.Text ellipsis style={{ ...FontMedium, color: theme.colorTextTertiary, maxWidth: 132 }}>
<View style={{ flexDirection: 'row', alignItems: 'center', gap: 16, justifyContent: 'flex-end', flex: 1 }}>
<Typography.Text ellipsis style={{ ...FontMedium, color: theme.colorTextTertiary, maxWidth: '80%' }}>
{currentDomain}
</Typography.Text>
<Typography.Text size={'md'} style={{ ...FontSemiBold, color: theme.colorWhite }}>
Expand Down
18 changes: 17 additions & 1 deletion src/components/WalletConnect/Network/WCNetworkAvatarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,23 @@ export const WCNetworkAvatarGroup = ({ networks }: Props) => {
</View>
);
})}
{countMore > 0 && <Typography.Text>+{countMore}</Typography.Text>}
{countMore > 0 && (
<Typography.Text
style={{
color: theme.colorWhite,
...FontBold,
position: 'absolute',
right: 4,
bottom: 0,
textAlign: 'center',
shadowOpacity: 1,
shadowColor: '#000000',
shadowRadius: 5,
}}
size={'sm'}>
+{countMore}
</Typography.Text>
)}
</View>
);
};
Expand Down
10 changes: 7 additions & 3 deletions src/components/common/AvatarGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ const AvatarGroup = ({ addresses: _addresses, avatarSize: _avatarSize }: Props)
}, [noAllAccount]);

const getAvatarStyle = useCallback(
(index: number) => {
(index: number, arrLength: number) => {
let avatarStyles: StyleProp<ViewStyle> = [_style.avatarContent];

if (index === 0) {
avatarStyles.push({ marginLeft: 0, opacity: 0.5 });
if (index === arrLength - 1) {
avatarStyles.push({ marginLeft: 0, opacity: 1 });
} else {
avatarStyles.push({ marginLeft: 0, opacity: 0.5 });
}
}

if (index === 2) {
Expand All @@ -64,7 +68,7 @@ const AvatarGroup = ({ addresses: _addresses, avatarSize: _avatarSize }: Props)
<View style={[_style.container, countMore > 0 && _style.mlStrong]}>
{noAllAccount.slice(0, 3).map((account, index) => {
return (
<View key={index} style={getAvatarStyle(index)}>
<View key={index} style={getAvatarStyle(index, noAllAccount.length)}>
<Avatar
size={avatarSize}
value={account}
Expand Down
5 changes: 2 additions & 3 deletions src/components/common/Modal/ConfirmModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { VoidFunction } from 'types/index';
import i18n from 'utils/i18n/i18n';
import createStyle from './styles';
import { noop } from 'utils/function';
import { useSafeAreaInsets } from 'react-native-safe-area-context';

interface Props {
message: string;
Expand All @@ -28,7 +27,6 @@ const ConfirmModal: React.FC<Props> = ({
}: Props) => {
const theme = useSubWalletTheme().swThemes;
const styles = useMemo(() => createStyle(theme), [theme]);
const insets = useSafeAreaInsets();

return (
<SwModal
Expand All @@ -37,9 +35,10 @@ const ConfirmModal: React.FC<Props> = ({
modalVisible={visible}
modalTitle={title}
titleTextAlign="center"
isUseModalV2
footer={
<>
<View style={[styles.footerModalStyle, { marginBottom: insets.bottom + 16 }]}>
<View style={styles.footerModalStyle}>
<Button type="secondary" style={{ flex: 1, marginRight: 12 }} onPress={onCancelModal}>
{i18n.common.cancel}
</Button>
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/Modal/ConfirmModal/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleSheet, TextStyle, ViewStyle } from 'react-native';
import { ThemeTypes } from 'styles/themes';
import { ContainerHorizontalPadding, FontMedium, FontSemiBold } from 'styles/sharedStyles';
import { FontMedium, FontSemiBold } from 'styles/sharedStyles';

export interface ModalStyle {
container: ViewStyle;
Expand All @@ -15,7 +15,7 @@ export default (theme: ThemeTypes) =>
footerModalStyle: {
width: '100%',
flexDirection: 'row',
...ContainerHorizontalPadding,
marginTop: theme.margin,
},
deleteModalConfirmationStyle: {
fontSize: theme.fontSizeLG,
Expand Down
3 changes: 1 addition & 2 deletions src/components/common/Modal/DeleteModal/styles/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StyleSheet, TextStyle, ViewStyle } from 'react-native';
import { ThemeTypes } from 'styles/themes';
import { ContainerHorizontalPadding, FontMedium, FontSemiBold, MarginBottomForSubmitButton } from 'styles/sharedStyles';
import { FontMedium, FontSemiBold, MarginBottomForSubmitButton } from 'styles/sharedStyles';

export interface ModalStyle {
container: ViewStyle;
Expand All @@ -14,7 +14,6 @@ export default (theme: ThemeTypes) =>
container: { width: '100%' },
footerModalStyle: {
width: '100%',
...ContainerHorizontalPadding,
...MarginBottomForSubmitButton,
paddingTop: theme.paddingXS,
},
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/screen/Transaction/useTransactionV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export const useTransaction = <T extends TransactionFormValues = TransactionForm
appModalContext.hideConfirmModal();
},
onCompleteModal: () => {
appModalContext.hideConfirmModal();
setTimeout(() => turnOnChain(chain), 200);
turnOnChain(chain);
setTimeout(() => appModalContext.hideConfirmModal(), 300);
},
messageIcon: chain,
});
Expand Down
30 changes: 30 additions & 0 deletions src/screens/Home/Browser/BrowserTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ import createStylesheet from './styles/BrowserTab';
import TabIcon from 'screens/Home/Browser/Shared/TabIcon';
import { RootState } from 'stores/index';
import { useSelector } from 'react-redux';
import urlParse from 'url-parse';
import { connectWalletConnect } from 'utils/walletConnect';
import { useToast } from 'react-native-toast-notifications';

export interface BrowserTabRef {
goToSite: (siteInfo: SiteInfo) => void;
Expand Down Expand Up @@ -148,6 +151,7 @@ const Component = ({ tabId, onOpenBrowserTabs, connectionTrigger }: Props, ref:
const hostname = siteUrl.current ? getHostName(siteUrl.current) : null;
const isNetConnected = useContext(WebRunnerContext).isNetConnected;
const isWebviewReady = !!(initWebViewSource && injectedScripts);
const toast = useToast();

const clearCurrentBrowserSv = () => {
browserSv.current?.onDisconnect();
Expand Down Expand Up @@ -414,6 +418,32 @@ const Component = ({ tabId, onOpenBrowserTabs, connectionTrigger }: Props, ref:
return false;
}

if (url.startsWith('wc:')) {
connectWalletConnect(url, toast);
return false;
}

const urlParsed = new urlParse(url);
console.log('url=====', url, urlParsed);
if (urlParsed.href.includes('wc?uri=wc')) {
Linking.canOpenURL(url)
.then(supported => {
if (supported) {
return Linking.openURL(url);
}
console.warn(`Can't open url: ${url}`);
return null;
})
.catch(e => {
console.warn(`Error opening URL: ${e}`);
});
return false;
}

if (urlParsed.href.startsWith('itms-appss://')) {
return false;
}

return true;
};

Expand Down
6 changes: 3 additions & 3 deletions src/screens/MasterPassword/CreateMasterPassword/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useMemo, useState } from 'react';
import { ContainerWithSubHeader } from 'components/ContainerWithSubHeader';
import { View } from 'react-native';
import { ScrollView, View } from 'react-native';
import { CheckCircle, Info } from 'phosphor-react-native';
import { Button, Icon, Typography } from 'components/design-system-ui';
import { useSubWalletTheme } from 'hooks/useSubWalletTheme';
Expand Down Expand Up @@ -116,7 +116,7 @@ const CreateMasterPassword = ({
disableRightButton={isBusy}
title={i18n.header.createAPassword}
style={{ width: '100%' }}>
<View style={_style.bodyWrapper}>
<ScrollView style={_style.bodyWrapper} keyboardShouldPersistTaps={'handled'} showsVerticalScrollIndicator={false}>
<Typography.Text style={_style.instructionTextStyle}>
{i18n.createPassword.createPasswordMessage}
</Typography.Text>
Expand Down Expand Up @@ -149,7 +149,7 @@ const CreateMasterPassword = ({
description={i18n.warning.warningPasswordMessage}
title={i18n.warning.warningPasswordTitle}
/>
</View>
</ScrollView>

<View style={_style.footerAreaStyle}>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default (theme: ThemeTypes) =>
paddingBottom: theme.paddingLG,
},
footerAreaStyle: {
marginTop: theme.marginXS,
marginTop: theme.margin,
marginHorizontal: theme.margin,
...MarginBottomForSubmitButton,
},
Expand Down
1 change: 1 addition & 0 deletions src/screens/Transaction/SendFundV2/Amount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ const Component = (props: InputAmountProps, ref: ForwardedRef<any>) => {
onChangeText={_onInputChange}
defaultValue={inputValue}
maxLength={getMaxLengthText(inputValue)}
autoFocus={true}
{...inputProps}
inputStyle={[stylesheet.input, inputStyle]}
containerStyle={[stylesheet.container, containerStyle]}
Expand Down

0 comments on commit e809398

Please sign in to comment.