invalid pkey message

This commit is contained in:
crptm 2017-07-04 16:19:04 +04:00
parent b5414c5f81
commit 9a65a49d0b
4 changed files with 31 additions and 22 deletions

View File

@ -1,8 +1,8 @@
// @flow
import type {
WalletAction,
SaveWalletAction,
InitWalletAction
SaveWalletAction
// InitWalletAction
} from 'actions/wallet';
import BaseWallet from 'libs/wallet/base';
@ -28,10 +28,7 @@ function initWallet(state: State): State {
return { ...state, balance: 0, tokens: {} };
}
export function wallet(
state: State = initialState,
action: WalletAction
): State {
export function wallet(state: State = initialState, action: WalletAction): State {
switch (action.type) {
case 'WALLET_SAVE':
return saveWallet(state, action);

View File

@ -4,7 +4,9 @@ import type { Effect } from 'redux-saga/effects';
import { delay } from 'redux-saga';
import { saveWallet, initWallet } from 'actions/wallet';
import type { UnlockPrivateKeyAction } from 'actions/wallet';
import { showNotification } from 'actions/notifications';
import PrivKeyWallet from 'libs/wallet/privkey';
import translate from 'translations';
function* init() {
yield put(initWallet());
@ -15,9 +17,16 @@ function* init() {
yield delay(100);
}
function* unlockPrivateKey(action?: UnlockPrivateKeyAction) {
export function* unlockPrivateKey(action?: UnlockPrivateKeyAction): Generator<Effect, void, any> {
if (!action) return;
yield put(saveWallet(new PrivKeyWallet(action.payload)));
let wallet = null;
try {
wallet = new PrivKeyWallet(action.payload);
} catch (e) {
yield put(showNotification('danger', translate('INVALID_PKEY')));
return;
}
yield put(saveWallet(wallet));
yield call(init);
}

View File

@ -1,16 +1,7 @@
{
"moduleFileExtensions": ["js", "jsx"],
"testPathIgnorePatterns": ["<rootDir>/common/config"],
"setupFiles": ["<rootDir>/jest_config/setupJest.js"],
"automock": false,
"moduleNameMapper": {
"^actions$": "<rootDir>/common/actions",
"^api": "<rootDir>/common/api",
"^reducers$": "<rootDir>/common/reducers",
"^routing": "<rootDir>/common/routing",
"^components$": "<rootDir>/common/components",
"^containers$": "<rootDir>/common/containers",
"^translations(.*)": "<rootDir>/common/translations$1",
"^libs(.*)": "<rootDir>/common/libs$1"
}
"moduleFileExtensions": ["js", "jsx"],
"testPathIgnorePatterns": ["<rootDir>/common/config"],
"setupFiles": ["<rootDir>/jest_config/setupJest.js"],
"automock": false,
"moduleDirectories": ["node_modules", "common"]
}

12
spec/sagas/wallet.spec.js Normal file
View File

@ -0,0 +1,12 @@
import { unlockPrivateKey } from 'sagas/wallet';
describe('Wallet saga', () => {
it('Should show error notification on decryption failure', () => {
const gen = unlockPrivateKey({
key: '0000000000000000000000000000000000000000000000000000000000000000'
});
// FIXME fragile
expect(gen.next().value.PUT.action.type).toEqual('SHOW_NOTIFICATION');
expect(gen.next().done).toBeTruthy();
});
});