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 throw {code: 'F_BTM001'}
38 const checkPassword = (data) => (dispatch) => {
39 return clientApi().checkPassword(data)
41 if(resp.status === 'fail'){
43 }else if(!resp.data.checkResult){
44 throw {code: 'F_BTM000'}
46 dispatch({ type: 'KEY_PASSWORD_SUCCESS'})
50 const createExport = (arg, fileName) => (dispatch) => {
51 clientApi().export(arg).then(resp => {
52 if(resp.status == 'success'){
53 const privateKey = resp.data.privateKey
55 var element = document.createElement('a')
56 element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(privateKey))
57 element.setAttribute('download', fileName)
58 element.style.display = 'none'
59 document.body.appendChild(element)
62 document.body.removeChild(element)
63 }else if(resp.status == 'fail'){
64 dispatch({ type: 'ERROR', payload: {message: resp.msg} })