Skip to content

Commit

Permalink
Add export seed phrase (#1218)
Browse files Browse the repository at this point in the history
* remove unused function

* add export seed phrase

* Update main/app-menu.js

Co-authored-by: Miroslav Bajtoš <oss@bajtos.net>

* move to tray, add confirmation dialog

---------

Co-authored-by: Miroslav Bajtoš <oss@bajtos.net>
  • Loading branch information
juliangruber and bajtos authored Apr 2, 2024
1 parent f5d92d9 commit 923a47e
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 47 deletions.
16 changes: 1 addition & 15 deletions main/dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ const { dialog } = require('electron')
/** @typedef {import('./typings').Context} Context */

module.exports = {
showDialogSync,
setup
showDialogSync
}

/**
Expand Down Expand Up @@ -55,16 +54,3 @@ function showDialogSync ({
? buttons.length - selected - 1
: selected
}

function setup (/** @type {Context} */ ctx) {
ctx.confirmChangeWalletAddress = () => {
const choice = showDialogSync({
title: 'You\'re about to change the FIL address',
message:
'Are you sure you want to change your wallet address? This will stop ' +
'all Station activity.',
buttons: ['Continue', 'Cancel']
})
return choice === 0
}
}
3 changes: 0 additions & 3 deletions main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const setupTray = require('./tray')
const setupUI = require('./ui')
const setupUpdater = require('./updater')
const Sentry = require('@sentry/node')
const { setup: setupDialogs } = require('./dialog')
const telemetry = require('./telemetry')

const inTest = (process.env.NODE_ENV === 'test')
Expand Down Expand Up @@ -128,7 +127,6 @@ const ctx = {
loadWebUIFromDist: serve({
directory: path.resolve(__dirname, '../renderer/dist')
}),
confirmChangeWalletAddress: () => { throw new Error('never get here') },
restartToUpdate: () => { throw new Error('never get here') },
openReleaseNotes: () => { throw new Error('never get here') },
getUpdaterStatus: () => { throw new Error('never get here') },
Expand Down Expand Up @@ -165,7 +163,6 @@ async function run () {

try {
setupTray(ctx)
setupDialogs(ctx)
if (process.platform === 'darwin') {
await setupAppMenu(ctx)
}
Expand Down
4 changes: 0 additions & 4 deletions main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ function setupIpcMain (/** @type {Context} */ ctx) {
ipcMain.handle(
'station:getTotalJobsCompleted',
(_event, _args) => ctx.getTotalJobsCompleted())
ipcMain.handle(
'dialogs:confirmChangeWalletAddress',
(_event, _args) => ctx.confirmChangeWalletAddress()
)

ipcMain.handle(
'station:restartToUpdate',
Expand Down
4 changes: 0 additions & 4 deletions main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,5 @@ contextBridge.exposeInMainWorld('electron', {
return () =>
ipcRenderer.removeListener('station:scheduled-rewards-update', listener)
}
},
dialogs: {
confirmChangeWalletAddress: () =>
ipcRenderer.invoke('dialogs:confirmChangeWalletAddress')
}
})
19 changes: 18 additions & 1 deletion main/tray.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict'

const { IS_MAC, STATION_VERSION } = require('./consts')
const { Menu, Tray, app, ipcMain, nativeImage } = require('electron')
const { Menu, Tray, app, ipcMain, nativeImage, clipboard } = require('electron')
const { ipcMainEvents } = require('./ipc')
const path = require('path')
const assert = require('node:assert')
const core = require('./core')
const { formatTokenValue } = require('./utils')
const { getSeedPhrase } = require('./wallet')
const { showDialogSync } = require('./dialog')

/** @typedef {import('./typings').Context} Context */

Expand Down Expand Up @@ -93,6 +95,21 @@ const createContextMenu = (/** @type {Context} */ ctx) => {
ctx.saveModuleLogsAs()
}
},
{
label: 'Export Seed Phrase…',
click: async () => {
const button = showDialogSync({
title: 'Export Seed Phrase',
// eslint-disable-next-line max-len
message: 'The seed phrase is used in order to back up your wallet, or move it to a different machine. Please be cautious, as anyone with access to it has full control over your wallet and funds.',
type: 'info',
buttons: ['Cancel', 'Copy to Clipboard']
})
if (button === 1) {
clipboard.writeText(await getSeedPhrase())
}
}
},
{ type: 'separator' },
{
label: 'Start at login',
Expand Down
1 change: 0 additions & 1 deletion main/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export interface Context {
loadWebUIFromDist: import('electron-serve').loadURL;
manualCheckForUpdates: () => void;
saveModuleLogsAs: () => Promise<void>;
confirmChangeWalletAddress: () => boolean;

openReleaseNotes: () => void;
restartToUpdate: () => void;
Expand Down
11 changes: 10 additions & 1 deletion main/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ function loadScheduledRewards () {
)
}

/**
* @returns {Promise<string>}
*/
async function getSeedPhrase () {
const { seed } = await backend.getSeedPhrase()
return seed
}

module.exports = {
setup,
refreshState,
Expand All @@ -250,5 +258,6 @@ module.exports = {
setScheduledRewards,
listTransactions,
transferAllFundsToDestinationWallet,
getTransactionsForUI
getTransactionsForUI,
getSeedPhrase
}
3 changes: 0 additions & 3 deletions renderer/src/lib/dialogs.tsx

This file was deleted.

5 changes: 1 addition & 4 deletions renderer/src/test/dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ describe('Dashboard page', () => {
onScheduledRewardsUpdate,
onBalanceUpdate
},
getUpdaterStatus: vi.fn(() => new Promise((resolve, reject) => ({}))),
dialogs: {
confirmChangeWalletAddress: () => Promise.resolve(true)
}
getUpdaterStatus: vi.fn(() => new Promise((resolve, reject) => ({})))
}
})
render(<BrowserRouter><Dashboard /></BrowserRouter>)
Expand Down
5 changes: 1 addition & 4 deletions renderer/src/test/wallet-interaction.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ describe('Dashboard wallet interactions', () => {
onScheduledRewardsUpdate,
onBalanceUpdate
},
getUpdaterStatus: vi.fn(() => new Promise((resolve, reject) => ({}))),
dialogs: {
confirmChangeWalletAddress: () => Promise.resolve(true)
}
getUpdaterStatus: vi.fn(() => new Promise((resolve, reject) => ({})))
}
})
render(<BrowserRouter><Dashboard /></BrowserRouter>)
Expand Down
5 changes: 1 addition & 4 deletions renderer/src/test/wallet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ describe('Dashboard wallet display', () => {
onBalanceUpdate,
onScheduledRewardsUpdate
},
getUpdaterStatus: vi.fn(() => new Promise((resolve, reject) => ({}))),
dialogs: {
confirmChangeWalletAddress: () => Promise.resolve(true)
}
getUpdaterStatus: vi.fn(() => new Promise((resolve, reject) => ({})))
}
})
render(<BrowserRouter><Dashboard /></BrowserRouter>)
Expand Down
3 changes: 0 additions & 3 deletions renderer/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ declare global {
onBalanceUpdate: (callback: (balance: string) => void) => () => void;
onScheduledRewardsUpdate: (callback: (balance: string) => void) => () => void;
};
dialogs: {
confirmChangeWalletAddress: () => Promise<boolean>;
};
};
}
}
Expand Down

0 comments on commit 923a47e

Please sign in to comment.