Skip to content

Commit

Permalink
Move export wallet actions to actions/wallet.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidTranDucVL committed Apr 7, 2021
1 parent fa1b402 commit 407f88c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
2 changes: 0 additions & 2 deletions app/frontend/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import addressActions from './actions/address'
import commonActions from './actions/common'
import delegateActions from './actions/delegate'
import errorActions from './actions/error'
import exportWalletActions from './actions/exportWallet'
import generalActions from './actions/general'
import loadingActions from './actions/loading'
import mnemonicActions from './actions/mnemonic'
Expand All @@ -19,7 +18,6 @@ export default (store: Store) => ({
...commonActions(store),
...delegateActions(store),
...errorActions(store),
...exportWalletActions(store),
...generalActions(store),
...loadingActions(store),
...mnemonicActions(store),
Expand Down
21 changes: 0 additions & 21 deletions app/frontend/actions/exportWallet.ts

This file was deleted.

15 changes: 15 additions & 0 deletions app/frontend/actions/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {State, Store} from '../state'
import errorActions from './error'
import loadingActions from './loading'

import {saveAs} from '../libs/file-saver'
import {exportWalletSecretDef} from '../wallet/keypass-json'

// TODO: (refactor), this should not call "setState" as it is not action
const fetchConversionRates = async (conversionRates, setState) => {
try {
Expand Down Expand Up @@ -186,11 +189,23 @@ export default (store: Store) => {
window.history.pushState({}, '/', '/')
}

const exportJsonWallet = async (state, password, walletName) => {
const walletExport = JSON.stringify(
await exportWalletSecretDef(getWallet().getWalletSecretDef(), password, walletName)
)

const blob = new Blob([walletExport], {
type: 'application/json;charset=utf-8',
})
saveAs(blob, `${walletName}.json`)
}

return {
loadWallet,
reloadWalletInfo,
loadDemoWallet,
logout,
getShouldShowSaturatedBanner,
exportJsonWallet,
}
}

0 comments on commit 407f88c

Please sign in to comment.