Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add export seed phrase #1218

Merged
merged 7 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading