Skip to content

Commit

Permalink
refactor: using logger to log errors
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabadesso committed Apr 12, 2024
1 parent 034794e commit 9b85311
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/sagas/walletConnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ import {
} from 'redux-saga/effects';
import { eventChannel } from 'redux-saga';
import { get, values } from 'lodash';
import { Core } from '@walletconnect/core';
import { Web3Wallet } from '@walletconnect/web3wallet';

import { WalletConnectModalTypes } from '../components/WalletConnect/WalletConnectModal';
import {
Expand All @@ -79,6 +77,8 @@ import {
setWCConnectionFailed,
} from '../actions';
import { checkForFeatureFlag, getNetworkSettings, showPinScreenForResult } from './helpers';
import { isSESEnabled } from './ses';
import logger from '../logger';

const AVAILABLE_METHODS = {
HATHOR_SIGN_MESSAGE: 'hathor_signMessage',
Expand Down Expand Up @@ -106,11 +106,24 @@ function* isWalletConnectEnabled() {
function* init() {
try {
const walletConnectEnabled = yield call(isWalletConnectEnabled);
const sesEnabled = yield call(isSESEnabled);

if (!walletConnectEnabled) {
logger.debug('wallet connect not enabled');
return;
}

// Even if walletconnect is enabled, we don't want to load its dependencies
// when SES is not protecting our app, so ignore it.
if (!sesEnabled) {
return;
}

// Dynamically import walletconnect modules so that it's not loaded in case
// wallet connect is not enabled.
const { Core } = yield call(() => import('@walletconnect/core'));
const { Web3Wallet } = yield call(() => import('@walletconnect/web3wallet'));

const core = new Core({
projectId: WALLET_CONNECT_PROJECT_ID,
});
Expand Down Expand Up @@ -141,7 +154,7 @@ function* init() {

yield cancel();
} catch (error) {
console.error('Error loading wallet connect', error);
logger.error('Error loading wallet connect', error);
yield put(onExceptionCaptured(error));
}
}
Expand Down Expand Up @@ -231,7 +244,7 @@ export function* onSessionRequest(action) {
const activeSessions = yield call(() => web3wallet.getActiveSessions());
const requestSession = activeSessions[payload.topic];
if (!requestSession) {
console.error('Could not identify the request session, ignoring request..');
logger.error('Could not identify the request session, ignoring request..');
return;
}

Expand Down Expand Up @@ -284,7 +297,7 @@ export function* onSignMessageRequest(data) {
const wallet = yield select((state) => state.wallet);

if (!wallet.isReady()) {
console.error('Got a session request but wallet is not ready, ignoring..');
logger.error('Got a session request but wallet is not ready, ignoring..');
return;
}

Expand Down Expand Up @@ -358,7 +371,7 @@ export function* onSignMessageRequest(data) {
response,
}));
} catch (error) {
console.log('Captured error on signMessage: ', error);
logger.error('Captured error on signMessage: ', error);
yield put(onExceptionCaptured(error));
}
}
Expand Down Expand Up @@ -440,7 +453,7 @@ export function* onSessionProposal(action) {

yield call(refreshActiveSessions);
} catch (error) {
console.error('Error on sessionProposal: ', error);
logger.error('Error on sessionProposal: ', error);
yield put(onExceptionCaptured(error));
}
}
Expand Down

0 comments on commit 9b85311

Please sign in to comment.