10 changed files with 274 additions and 5 deletions
@ -0,0 +1,110 @@ |
|||||
|
import Config from '../../config'; |
||||
|
import { getDecryptedPassphrase, getPinList, triggerToaster } from "../actionCreators"; |
||||
|
import { iguanaWalletPassphrase } from "./walletAuth"; |
||||
|
|
||||
|
export function encryptPassphrase(passphrase, key, pubKey) { |
||||
|
const payload = { |
||||
|
'string': passphrase, |
||||
|
'key': key, |
||||
|
'pubkey': pubKey |
||||
|
}; |
||||
|
|
||||
|
return dispatch => { |
||||
|
return fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/encryptkey`, { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
}, |
||||
|
body: JSON.stringify(payload), |
||||
|
}) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'encryptKey', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
console.log('encrypt result', json); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'passphrase successfully encrypted', |
||||
|
'Success', |
||||
|
'success' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export function loginWithPin(key, pubKey) { |
||||
|
const payload = { |
||||
|
'key': key, |
||||
|
'pubkey': pubKey |
||||
|
}; |
||||
|
|
||||
|
return dispatch => { |
||||
|
return fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/decryptkey`, { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
}, |
||||
|
body: JSON.stringify(payload), |
||||
|
}) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'decryptKey', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
console.log('decrypt result', json); |
||||
|
dispatch(iguanaWalletPassphrase(json.result)); |
||||
|
}) |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export function loadPinList() { |
||||
|
return dispatch => { |
||||
|
return fetch(`http://127.0.0.1:${Config.agamaPort}/shepherd/getpinlist`, { |
||||
|
method: 'GET', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
} |
||||
|
}) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'getPinList', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
console.log('getpinlist result', json); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'getPinList', |
||||
|
'Success', |
||||
|
'success' |
||||
|
) |
||||
|
); |
||||
|
|
||||
|
dispatch( |
||||
|
getPinList(json.result) |
||||
|
) |
||||
|
}) |
||||
|
} |
||||
|
} |
@ -0,0 +1,19 @@ |
|||||
|
import {} from '../actions/storeType'; |
||||
|
import { GET_PIN_LIST } from "../actions/storeType"; |
||||
|
|
||||
|
export function login(state = { |
||||
|
pinList: [], |
||||
|
}, action) { |
||||
|
if (state === null) state = {toasts: []}; |
||||
|
|
||||
|
switch (action.type) { |
||||
|
case GET_PIN_LIST: |
||||
|
return Object.assign({}, state, { |
||||
|
pinList: action.pinList |
||||
|
}); |
||||
|
default: |
||||
|
return state; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default login; |
Loading…
Reference in new issue