backup/html/backup.jsView |
---|
1 | 1 | const nest = require('depnest') |
2 | | -const { h, computed, Value } = require('mutant') |
| 2 | +const { h, computed, Value, resolve } = require('mutant') |
3 | 3 | const electron = require('electron') |
| 4 | +const { dialog } = require('electron').remote; |
4 | 5 | const path = require('path') |
5 | 6 | const fs = require('fs') |
6 | 7 | |
7 | 8 | exports.gives = nest({ |
10 | 11 | |
11 | 12 | exports.needs = nest({ |
12 | 13 | 'app.html.lightbox': 'first', |
13 | 14 | 'keys.sync.id': 'first', |
14 | | - 'translations.sync.strings': 'first' |
| 15 | + 'translations.sync.strings': 'first', |
| 16 | + 'backup.async.exportIdentity': 'first' |
15 | 17 | }) |
16 | 18 | |
17 | 19 | exports.create = (api) => { |
18 | 20 | return nest('backup.html', { exportIdentityButton, importIdentityButton }) |
22 | 24 | |
23 | 25 | function exportIdentityButton() { |
24 | 26 | let isOpen = Value(false) |
25 | 27 | let encryptionKeyRaw = Value('') |
26 | | - let msg = "Your identity is represented by an ed25519 key pair. Please backup your private key file very carefully. If your private key is hacked, all your private messages will be retrieved by third party, and your identity will be faked on the network" |
| 28 | + |
27 | 29 | let encryptionKeyInput = h('textarea#encryptionKey', { |
28 | 30 | style: { |
29 | 31 | width: '90%' |
30 | 32 | }, |
32 | 34 | value: encryptionKeyRaw, |
33 | 35 | 'ev-input': () => encryptionKeyRaw.set(encryptionKeyInput.value), |
34 | 36 | }) |
35 | 37 | |
36 | | - let dialog = h('div.dialog', [ |
37 | | - h('div.message', [ |
38 | | - h('p', msg), |
39 | | - ]), |
40 | | - h('div.form', [ |
41 | | - encryptionKeyInput |
42 | | - ]), |
43 | | - h('div.actions', [ |
44 | | - h('Button', { 'ev-click': () => isOpen.set(false) }, 'Cancel'), |
45 | | - h('Button -primary', { 'ev-click': () => exportKey(resolve(encryptionKeyRaw), () => isOpen.set(false)) }, 'Export Keys') |
| 38 | + let exportDialog = h('div.dialog', { |
| 39 | + style: { |
| 40 | + 'text-align': 'left' |
| 41 | + } |
| 42 | + }, |
| 43 | + [ |
| 44 | + h('div.message', [ |
| 45 | + h('h1', 'Export Identity'), |
| 46 | + h('p', 'Please backup your private key file very carefully.'), |
| 47 | + h('p', 'If your private key is hacked, all your private messages will be retrieved by third party, and your identity will be faked on the network') |
| 48 | + ]), |
| 49 | + h('div.form', [ |
| 50 | + encryptionKeyInput |
| 51 | + ]), |
| 52 | + h('div.actions', [ |
| 53 | + h('Button', { 'ev-click': () => isOpen.set(false) }, 'Cancel'), |
| 54 | + h('Button -primary', { |
| 55 | + 'ev-click': () => { |
| 56 | + dialog.showSaveDialog( |
| 57 | + { |
| 58 | + title: 'Export Identity', |
| 59 | + butttonLabel: 'Export Identity', |
| 60 | + defaultPath: 'ticktack-identity.backup', |
| 61 | + }, |
| 62 | + (filename) => api.backup.async.exportIdentity( |
| 63 | + resolve(encryptionKeyRaw), filename, () => isOpen.set(false) |
| 64 | + ) |
| 65 | + ) |
| 66 | + } |
| 67 | + }, 'Export Identity') |
| 68 | + ]) |
46 | 69 | ]) |
47 | | - ]) |
48 | 70 | |
49 | | - let lb = api.app.html.lightbox(dialog, isOpen) |
| 71 | + let lb = api.app.html.lightbox(exportDialog, isOpen) |
50 | 72 | |
51 | 73 | return h('div.backupKeys', [ |
52 | 74 | h('Button -backup', { 'ev-click': () => isOpen.set(true) }, 'Export Keys'), |
53 | 75 | lb |