Skip to content

Commit

Permalink
Merge branch 'main' into add-android-detox-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cortisiko authored Jul 12, 2023
2 parents 2faf376 + ead1b05 commit 50caa84
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 13 deletions.
12 changes: 8 additions & 4 deletions app/components/Nav/App/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ import EthSignFriction from '../../../components/Views/Settings/AdvancedSettings
import WalletActions from '../../Views/WalletActions';
import NetworkSelector from '../../../components/Views/NetworkSelector';
import EditAccountName from '../../Views/EditAccountName/EditAccountName';
import WC2Manager from '../../../../app/core/WalletConnect/WalletConnectV2';
import WC2Manager, {
isWC2Enabled,
} from '../../../../app/core/WalletConnect/WalletConnectV2';

const clearStackNavigatorOptions = {
headerShown: false,
Expand Down Expand Up @@ -360,9 +362,11 @@ const App = ({ userLoggedIn }) => {
}, [navigator]);

useEffect(() => {
WC2Manager.init().catch((err) => {
console.error(`Cannot initialize WalletConnect Manager.`, err);
});
if (isWC2Enabled) {
WC2Manager.init().catch((err) => {
console.error('Cannot initialize WalletConnect Manager.', err);
});
}
}, []);

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,94 @@ exports[`Network Selector renders correctly 1`] = `
/>
</View>
</TouchableOpacity>
<TouchableOpacity
disabled={false}
onPress={[Function]}
style={
Object {
"opacity": 1,
"position": "relative",
}
}
>
<View
accessibilityRole="none"
accessible={true}
style={
Object {
"alignItems": "flex-start",
"backgroundColor": "#FFFFFF",
"borderRadius": 4,
"flexDirection": "row",
"padding": 16,
}
}
>
<View
style={
Object {
"flexDirection": "row",
}
}
>
<View
style={
Object {
"backgroundColor": "#FFFFFF",
"borderRadius": 16,
"height": 32,
"marginRight": 16,
"overflow": "hidden",
"width": 32,
}
}
>
<Image
onError={[Function]}
resizeMode="contain"
source={
Object {
"uri": "MockImage",
}
}
style={
Object {
"flex": 1,
"height": undefined,
"width": undefined,
}
}
testID="network-avatar-image"
/>
</View>
<View
style={
Object {
"alignItems": "flex-start",
"flex": 1,
}
}
>
<Text
numberOfLines={1}
style={
Object {
"color": "#24272A",
"fontFamily": "Euclid Circular B",
"fontSize": 16,
"fontWeight": "400",
"letterSpacing": 0,
"lineHeight": 24,
}
}
testID="cell-title"
>
Linea Main Network
</Text>
</View>
</View>
</View>
</TouchableOpacity>
<TouchableOpacity
disabled={false}
onPress={[Function]}
Expand Down
14 changes: 10 additions & 4 deletions app/components/Views/WalletConnectSessions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import Logger from '../../../util/Logger';
import { WALLETCONNECT_SESSIONS } from '../../../constants/storage';
import { ThemeContext, mockTheme } from '../../../util/theme';
import PropTypes from 'prop-types';
import WC2Manager from '../../../../app/core/WalletConnect/WalletConnectV2';
import WC2Manager, {
isWC2Enabled,
} from '../../../../app/core/WalletConnect/WalletConnectV2';

const createStyles = (colors) =>
StyleSheet.create({
Expand Down Expand Up @@ -112,13 +114,17 @@ export default class WalletConnectSessions extends PureComponent {

loadSessions = async () => {
let sessions = [];
let sessionsV2 = [];

const sessionData = await AsyncStorage.getItem(WALLETCONNECT_SESSIONS);
if (sessionData) {
sessions = JSON.parse(sessionData);
}

// Add wallet connect v2 sessions to the list
const sessionsV2 = (await WC2Manager.getInstance())?.getSessions() || [];
if (isWC2Enabled) {
// Add wallet connect v2 sessions to the list
sessionsV2 = (await WC2Manager.getInstance())?.getSessions() || [];
}

this.setState({ ready: true, sessions, sessionsV2 });
};
Expand Down Expand Up @@ -148,7 +154,7 @@ export default class WalletConnectSessions extends PureComponent {
killSession = async () => {
const isV2 = this.sessionToRemove.peerId === undefined;
try {
if (isV2) {
if (isV2 && isWC2Enabled) {
await (
await WC2Manager.getInstance()
)?.removeSession(this.sessionToRemove);
Expand Down
18 changes: 13 additions & 5 deletions app/core/WalletConnect/WalletConnectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ import parseWalletConnectUri from './wc-utils';
import AsyncStorage from '@react-native-async-storage/async-storage';
import METHODS_TO_REDIRECT from './wc-config';

const { PROJECT_ID } = AppConstants.WALLET_CONNECT;
export const isWC2Enabled =
typeof PROJECT_ID === 'string' && PROJECT_ID?.length > 0;

const ERROR_MESSAGES = {
INVALID_CHAIN: 'Invalid chainId',
MANUAL_DISCONNECT: 'Manual disconnect',
Expand Down Expand Up @@ -366,12 +370,16 @@ export class WC2Manager {

let core;
try {
core = new Core({
projectId: AppConstants.WALLET_CONNECT.PROJECT_ID,
// logger: 'debug',
});
if (typeof PROJECT_ID === 'string') {
core = new Core({
projectId: PROJECT_ID,
// logger: 'debug',
});
} else {
throw new Error('WC2::init Init Missing projectId');
}
} catch (err) {
console.warn(`WC2::init Init failed due to missing key: ${err}`);
console.warn(`WC2::init Init failed due to ${err}`);
}

let web3Wallet;
Expand Down

0 comments on commit 50caa84

Please sign in to comment.