1 import { baseListActions, baseCreateActions } from 'features/shared/actions'
2 import { chainClient } from 'utility/environment'
3 import {push} from 'react-router-redux'
6 const clientApi = () => chainClient().mockHsm.keys
8 const list = baseListActions(type, {
12 const create = baseCreateActions(type, {
17 const resetPassword = {
18 submitResetForm: (params) => {
19 let promise = Promise.resolve()
20 return (dispatch) => {
21 return promise.then(() => clientApi().resetPassword(params).then((resp) => {
22 if(resp.data.changed){
23 dispatch({ type: `RESET_PASSWORD_${type.toUpperCase()}`, resp })
25 pathname: `/${type}s/${params.xpub}`,
31 let msg = 'Unable to reset the key password.'
39 const checkPassword = (data) => (dispatch) => {
40 return clientApi().checkPassword(data)
42 if(resp.status === 'fail'){
43 throw new Error(resp.msg)
44 }else if(!resp.data.checkResult){
45 throw new Error('Your Password is wrong')
47 dispatch({ type: 'KEY_PASSWORD_SUCCESS'})
51 const createExport = (arg, fileName) => (dispatch) => {
52 clientApi().export(arg).then(resp => {
53 if(resp.status == 'success'){
54 const privateKey = resp.data.privateKey
56 var element = document.createElement('a')
57 element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(privateKey))
58 element.setAttribute('download', fileName)
59 element.style.display = 'none'
60 document.body.appendChild(element)
63 document.body.removeChild(element)
64 }else if(resp.status == 'fail'){
65 dispatch({ type: 'ERROR', payload: {message: resp.msg} })