Skip to content

Commit

Permalink
Release 1.9.3 (#2587)
Browse files Browse the repository at this point in the history
* fix: disable notaries application button while loading kyc requirements (#2571)

* Fix passports marketplace missing data check (#2572)

* feat: WalletConnect (#2580)

* feat: update selfkey-ui

* feat: WalletConnect scan qr-code and manage sessions (#2579)

* feat: refactor deep link WalletConnect connector

* feat: ui adjustments to WalletConnect sign and transaction screens (#2579)

* fix: dashboard token list UI fix (#2581)

* fix: default gas and nonce (#2583)

* fix: frameless border and sidebar in windows (#2586)

* feat: safe gas multiplier (#2585)

* feat(version): bump to 1.9.3

Co-authored-by: Kovalov Maxim <max.kovalov@gmail.com>
Co-authored-by: Maycon Mello <maycon.mellos@gmail.com>
Co-authored-by: Andre Goncalves <andre@andregoncalves.com>
  • Loading branch information
3 people authored May 4, 2021
1 parent aeb888d commit 9baa003
Show file tree
Hide file tree
Showing 37 changed files with 11,610 additions and 192 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "selfkey-identity-wallet",
"productName": "SelfKey Identity Wallet",
"version": "1.9.2",
"version": "1.9.3",
"description": "The Official SelfKey Identity Wallet for Desktop",
"browser": [
"chrome"
Expand Down Expand Up @@ -80,7 +80,7 @@
"@reduxjs/toolkit": "1.5.0",
"@sentry/electron": "0.17.1",
"@trodi/electron-splashscreen": "0.3.4",
"@walletconnect/client": "1.3.1",
"@walletconnect/client": "^1.4.1",
"@walletconnect/utils": "1.3.1",
"ajv": "6.10.0",
"async": "2.6.2",
Expand Down Expand Up @@ -140,7 +140,7 @@
"reselect": "4.0.0",
"sanitize-html": "1.20.0",
"scrypt": "6.0.3",
"selfkey-ui": "https://github.com/SelfKeyFoundation/selfkey-ui.git#945f6987ca05a36ca2b32f0e02b9351f9105329d",
"selfkey-ui": "https://github.com/SelfKeyFoundation/selfkey-ui.git#5e1fae23177a5d03435a761749cdd92582842549",
"selfkey.js": "1.0.24",
"serialize-error": "3.0.0",
"snyk": "1.235.0",
Expand Down Expand Up @@ -265,7 +265,7 @@
"react": "16.13.1",
"react-dom": "16.13.1",
"react-jsonschema-form-material-theme": "https://github.com/SelfKeyFoundation/react-jsonschema-form-material-theme.git#e8356d2037b527f7b0a8433f20c476b6e501d70e",
"selfkey-ui": "https://github.com/SelfKeyFoundation/selfkey-ui.git#945f6987ca05a36ca2b32f0e02b9351f9105329d",
"selfkey-ui": "https://github.com/SelfKeyFoundation/selfkey-ui.git#5e1fae23177a5d03435a761749cdd92582842549",
"@material-ui/styles": "4.9.6",
"@material-ui/core": "4.9.10"
},
Expand Down
3 changes: 3 additions & 0 deletions src/common/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const REWARD_TOKEN = process.env.REWARD_TOKEN_OVERRIDE
? process.env.REWARD_TOKEN_OVERRIDE.toUpperCase()
: null;

const SAFE_GAS_MULTIPLIER = +process.env.SAFE_GAS_MULTIPLIER;

// KYCC ENV variables
const KYCC_API_OVERRIDE = process.env.KYCC_API_OVERRIDE;
// Incorporations ENV variables
Expand Down Expand Up @@ -64,6 +66,7 @@ const common = {
defaultLanguage: 'en',
forceUpdateAttributes: process.env.FORCE_UPDATE_ATTRIBUTES === 'true' && !isTestMode(),
userAgent: `SelfKeyIDW/${pkg.version}`,
safeGasMultiplier: SAFE_GAS_MULTIPLIER || 1.5,
airtableBaseUrl: 'https://airtable.selfkey.org/airtable?tableName=',

exchangeRateApiUrl: 'https://api.exchangeratesapi.io',
Expand Down
128 changes: 121 additions & 7 deletions src/common/wallet-connect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ import { getGlobalContext } from '../context';
import { createAliasedAction } from 'electron-redux';
import { push } from 'connected-react-router';
import { getWallet } from '../wallet/selectors';
import { getTransactionCount } from 'common/transaction/operations';
import { Logger } from 'common/logger';
const log = new Logger('WalletConnectDuck');

let hardwalletConfirmationTimeout = null;

export const walletConnectInitialState = {
confirmConnection: null,
uri: null,
isLoading: false,
pendingUri: null,
unlocked: false,
sessions: [],
nonce: null,
hasSessionRequest: false,
hasSignRequest: false,
hasTxRequest: false,
Expand All @@ -21,6 +29,7 @@ export const walletConnectInitialState = {
};

export const walletConnectTypes = {
WALLET_CONNECT_HANDLE_URI_OPERATION: 'wallet-connect/session/operation/HANDLE_URI',
WALLET_CONNECT_SESSION_REQUEST_OPERATION: 'wallet-connect/session/operation/REQUEST',
WALLET_CONNECT_SESSION_REQUEST_APPROVE_OPERATION:
'wallet-connect/session/operation/REQUEST_APPROVE',
Expand All @@ -32,7 +41,13 @@ export const walletConnectTypes = {
WALLET_CONNECT_TRANSACTION_DENY_OPERATION: 'wallet-connect/transaction/operation/DENY',
WALLET_CONNECT_TRANSACTION_APPROVE_OPERATION: 'wallet-connect/transaction/operation/APPROVE',
WALLET_CONNECT_SESSION_SET: 'wallet-connect/session/SET',
WALLET_CONNECT_SESSION_RESET: 'wallet-connect/session/RESET'
WALLET_CONNECT_SESSION_RESET: 'wallet-connect/session/RESET',
WALLET_CONNECT_URI_SET: 'wallet-connect/uri/SET',
WALLET_CONNECT_CONFIRM_CONNECTION_SET: 'wallet-connect/confirm/connection/SET',
WALLET_CONNECT_SESSIONS_LOAD_OPERATION: 'wallet-connect/sessions/operation/LOAD',
WALLET_CONNECT_SESSIONS_SET: 'wallet-connect/sessions/SET',
WALLET_CONNECT_SESSION_DELETE_OPERATION: 'wallet-connet/session/DELETE',
WALLET_CONNECT_SCAN_QR_CODE_OPERATION: 'wallet-connect/session/qr-code/SCAN'
};

export const walletConnectActions = {
Expand All @@ -43,6 +58,18 @@ export const walletConnectActions = {
resetSessionAction: payload => ({
type: walletConnectTypes.WALLET_CONNECT_SESSION_RESET,
payload
}),
setUri: payload => ({
type: walletConnectTypes.WALLET_CONNECT_URI_SET,
payload
}),
setConfirmConnection: payload => ({
type: walletConnectTypes.WALLET_CONNECT_CONFIRM_CONNECTION_SET,
payload
}),
setSessions: payload => ({
type: walletConnectTypes.WALLET_CONNECT_SESSIONS_SET,
payload
})
};

Expand All @@ -52,39 +79,90 @@ export const reducers = {
},
resetSessionReducer: () => {
return { ...walletConnectInitialState };
},
setUriReducer: (state, action) => {
return { ...state, uri: action.payload };
},
setConfirmConnectionReducer: (state, action) => {
return { ...state, confirmConnection: action.payload };
},
setSessionsReducer: (state, action) => {
return { ...state, sessions: action.payload };
}
};

export const operations = {
...walletConnectActions,
sessionRequestOperation: (peerId, peerMeta) => async (dispatch, getState) => {

handleUri: uri => async (dispatch, getState) => {
// const wallet = getWallet(getState());
const { walletConnectService } = getGlobalContext();
await dispatch(operations.setSessionAction({ isLoading: true }));
await walletConnectService.handleSession(uri);
},
loadSessions: () => async (dispatch, getState) => {
const { walletConnectService } = getGlobalContext();
const sessions = await walletConnectService.getSessions();
dispatch(walletConnectActions.setSessions(sessions));
},
deleteSession: session => async (dispatch, getState) => {
const { walletConnectService } = getGlobalContext();
if (!session || !session.id) throw new Error('No session id found');
await walletConnectService.killSession(session.id);
console.log(session.id);
dispatch(operations.loadSessions);
},
sessionRequestOperation: (peerId, peerMeta, uri, confirmConnection) => async (
dispatch,
getState
) => {
await dispatch(operations.resetSessionAction());
await dispatch(
operations.setSessionAction({
hasSessionRequest: true,
peerId,
peerMeta
peerMeta,
uri,
confirmConnection,
isLoading: false
})
);
await dispatch(push('/wallet-connect/approve-session'));
},
sessionRequestDenyOperation: () => async (dispatch, getState) => {
const wallet = getWallet(getState());
const { walletConnectService } = getGlobalContext();
if (!wallet) throw new Error('No wallet selected');

const { uri } = walletConnectSelectors.selectWalletConnect(getState());
if (!uri) throw new Error('No wc URI detected');

walletConnectService.rejectSession();
await walletConnectService.rejectSession(uri);
await dispatch(operations.resetSessionAction());
if (wallet && wallet.address) {
return dispatch(push('/main/dashboard'));
}

return dispatch(push('/home'));
},
sessionRequestApproveOperation: () => async (dispatch, getState) => {
const { walletConnectService } = getGlobalContext();
const wallet = getWallet(getState());
if (!wallet) throw new Error('No wallet selected');
walletConnectService.approveSession(wallet.address);

const { peerMeta, uri, confirmConnection } = walletConnectSelectors.selectWalletConnect(
getState()
);
if (!confirmConnection) throw new Error('No wc confirm connection detected');
if (!uri) throw new Error('No wc URI detected');

const session = await walletConnectService.approveSession(
wallet.address,
uri,
confirmConnection,
peerMeta
);
if (!session) throw new Error('WalletConnect session not detected');

await dispatch(operations.resetSessionAction());
return dispatch(push('/main/dashboard'));
},
Expand Down Expand Up @@ -171,6 +249,7 @@ export const operations = {
if (!wallet || !wallet.address) {
throw new Error('Cannot sign message without wallet');
}
const nonce = await getTransactionCount(wallet.address);
await dispatch(operations.resetSessionAction());
await dispatch(
operations.setSessionAction({
Expand All @@ -180,7 +259,8 @@ export const operations = {
peerId,
tx,
method,
rawTx
rawTx,
nonce
})
);
await dispatch(push('/wallet-connect/transaction'));
Expand Down Expand Up @@ -256,11 +336,28 @@ export const operations = {
log.error(error);
throw error;
}
},
scanQRCode: () => async (dispatch, getState) => {
try {
const { walletConnectService } = getGlobalContext();
walletConnectService.scanQrCode();
} catch (error) {
log.error(error);
throw error;
}
}
};

export const walletConnectOperations = {
...walletConnectActions,
handleUriOperation: createAliasedAction(
walletConnectTypes.WALLET_CONNECT_HANDLE_URI_OPERATION,
operations.handleUri
),
loadSessionsOperation: createAliasedAction(
walletConnectTypes.WALLET_CONNECT_SESSIONS_LOAD_OPERATION,
operations.loadSessions
),
sessionRequestOperation: createAliasedAction(
walletConnectTypes.WALLET_CONNECT_SESSION_REQUEST_OPERATION,
operations.sessionRequestOperation
Expand Down Expand Up @@ -296,11 +393,22 @@ export const walletConnectOperations = {
transactionApproveOperation: createAliasedAction(
walletConnectTypes.WALLET_CONNECT_TRANSACTION_APPROVE_OPERATION,
operations.transactionApproveOperation
),
deleteSessionOperation: createAliasedAction(
walletConnectTypes.WALLET_CONNECT_SESSION_DELETE_OPERATION,
operations.deleteSession
),
scanQRCodeOperation: createAliasedAction(
walletConnectTypes.WALLET_CONNECT_SCAN_QR_CODE_OPERATION,
operations.scanQRCode
)
};

export const walletConnectSelectors = {
selectWalletConnect: state => state.walletConnect,
selectUri: state => walletConnectSelectors.selectWalletConnect(state).uri,
selectConfirmConnection: state =>
walletConnectSelectors.selectWalletConnect(state).confirmConnection,
hasSessionRequest: state => walletConnectSelectors.selectWalletConnect(state).hasSessionRequest,
hasSignMessageRequest: state =>
walletConnectSelectors.selectWalletConnect(state).hasSignMessageRequest
Expand All @@ -312,6 +420,12 @@ export const walletConnectReducer = (state = walletConnectInitialState, action)
return reducers.setSessionRequestReducer(state, action);
case walletConnectTypes.WALLET_CONNECT_SESSION_RESET:
return reducers.resetSessionReducer(state, action);
case walletConnectTypes.WALLET_CONNECT_URI_SET:
return reducers.setUriReducer(state, action);
case walletConnectTypes.WALLET_CONNECT_CONFIRM_CONNECTION_SET:
return reducers.setConfirmConnectionReducer(state, action);
case walletConnectTypes.WALLET_CONNECT_SESSIONS_SET:
return reducers.setSessionsReducer(state, action);
}
return state;
};
Expand Down
6 changes: 3 additions & 3 deletions src/main/application/deeplink-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ export class DeepLinksService {

handleOpenLink = async url => {
try {
log.info('incoming deep link %s', url);
log.info('Incoming deep link %s', url);
const urlRegexp = /^[^:/]*:\/\/([^/]*)\/(.*)$/;
const match = (url || '').match(urlRegexp);
if (!match || match.length !== 3) {
log.info('invalid deep link format');
log.error('invalid deep link format');
return;
}
if (!this.handlers[match[1]]) {
log.info('no handler for %s', match[1]);
return;
}

await this.handlers[match[1]].handleUrlCommand(match[2]);
await this.handlers[match[1]].handleSession(match[2]);
} catch (error) {
log.error(error);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function onWindowAllClosed() {
return () => {
log.debug('all windows closed, quitting');
const ctx = getGlobalContext();
ctx.walletConnectService.killSession();
ctx.walletConnectService.killSessions();
return electron.app.quit();
};
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/migrations/20210420093508_wallet_connect_sessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
exports.up = async (knex, Promise) => {
try {
await knex.schema.createTable('wallet_connect_sessions', t => {
t.increments('id');
t.string('address');
t.string('session');
t.string('name');
t.string('url');
t.string('icon');
t.integer('createdAt').notNullable();
t.integer('updatedAt');
});
} catch (error) {
console.error(error);
throw error;
}
};

exports.down = async (knex, Promise) => {
await knex.schema.dropTable('wallet_connect_sessions');
};
12 changes: 11 additions & 1 deletion src/main/token/token-service.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
import config from 'common/config';
import Token from './token';
import { getGlobalContext } from 'common/context';
import { BigNumber } from 'bignumber.js';
Expand Down Expand Up @@ -51,6 +52,15 @@ export class TokenService {
};
}

/**
*
* @param {*} contractAddress
* @param {*} address
* @param {*} amount
* @param {*} decimal
* @param {*} fromAddress
* @returns
*/
async getGasLimit(contractAddress, address, amount, decimal, fromAddress) {
const tokenContract = new this.web3Service.web3.eth.Contract(
this.contractABI,
Expand All @@ -63,7 +73,7 @@ export class TokenService {
const estimate = await tokenContract.methods
.transfer(address, amountWithDecimals)
.estimateGas({ from: fromAddress });
return Math.round(Math.min(estimate * 1.1, MAX_GAS));
return Math.round(Math.min(estimate * config.safeGasMultiplier, MAX_GAS));
}
}

Expand Down
Loading

0 comments on commit 9baa003

Please sign in to comment.