invalid pkey message
This commit is contained in:
parent
b5414c5f81
commit
9a65a49d0b
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,14 +3,5 @@
|
|||
"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"
|
||||
}
|
||||
"moduleDirectories": ["node_modules", "common"]
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue