Skip to content

Commit

Permalink
Merge branch 'develop' into refactor/remove-unexpected-async-code
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkNerdi authored May 8, 2024
2 parents 7a665da + faa12cc commit 8a1a415
Show file tree
Hide file tree
Showing 67 changed files with 591 additions and 398 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@types/node": "18.15.11",
"eslint": "8.42.0",
"eslint-plugin-security": "1.7.1",
"eslint-plugin-svelte": "2.36.0",
"eslint-plugin-svelte": "2.38.0",
"husky": "7.0.4",
"lint-staged": "12.5.0",
"patch-package": "8.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
} from '@iota/sdk/out/types'
import { closePopup } from '@desktop/auxiliary/popup'
import { api, getClient } from '@core/profile-manager'
import { formatTokenAmountPrecise } from '@core/token'
import { formatTokenAmountBestMatch } from '@core/token'
import { getActiveNetworkId } from '@core/network'
import PopupTemplate from '../PopupTemplate.svelte'
Expand All @@ -38,7 +38,7 @@
try {
const client = await getClient()
const resp = await client.buildAliasOutput(params)
storageDeposit = formatTokenAmountPrecise(Number(resp.amount), getBaseToken())
storageDeposit = formatTokenAmountBestMatch(BigInt(resp.amount), getBaseToken())
} catch (err) {
handleError(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { getBaseToken, checkActiveProfileAuth } from '@core/profile/actions'
import { mintNativeToken, mintTokenDetails, buildFoundryOutputBuilderParams, IMintTokenDetails } from '@core/wallet'
import { closePopup, openPopup, PopupId } from '@desktop/auxiliary/popup'
import { IIrc30Metadata, TokenStandard, formatTokenAmountPrecise } from '@core/token'
import { IIrc30Metadata, TokenStandard, formatTokenAmountBestMatch } from '@core/token'
import { getClient } from '@core/profile-manager'
import PopupTemplate from '../PopupTemplate.svelte'
Expand All @@ -28,7 +28,7 @@
)
const client = await getClient()
const preparedOutput = await client.buildFoundryOutput(foundryOutputParams)
storageDeposit = formatTokenAmountPrecise(Number(preparedOutput.amount) ?? 0, getBaseToken())
storageDeposit = formatTokenAmountBestMatch(BigInt(preparedOutput.amount ?? 0), getBaseToken())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts'
import { getClient } from '@core/profile-manager'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { formatTokenAmountPrecise } from '@core/token'
import { formatTokenAmountBestMatch } from '@core/token'
import { buildNftOutputBuilderParams, mintNftCollection, mintNftCollectionDetails } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { MediaIcon, PopupTab, getTabItems } from '@ui'
Expand Down Expand Up @@ -103,7 +103,7 @@
items={[
{
key: localize('general.storageDeposit'),
value: formatTokenAmountPrecise(storageDeposit, getBaseToken()),
value: formatTokenAmountBestMatch(BigInt(storageDeposit), getBaseToken()),
},
{
key: localize('general.immutableIssuer'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { CURRENT_IRC27_VERSION, IIrc27Metadata } from '@core/nfts'
import { getClient } from '@core/profile-manager'
import { checkActiveProfileAuth, getBaseToken } from '@core/profile/actions'
import { formatTokenAmountPrecise } from '@core/token'
import { formatTokenAmountBestMatch } from '@core/token'
import { buildNftOutputBuilderParams, mintNft, mintNftDetails } from '@core/wallet'
import { PopupId, closePopup, openPopup } from '@desktop/auxiliary/popup'
import { MediaIcon, PopupTab, getTabItems } from '@ui'
Expand Down Expand Up @@ -125,20 +125,22 @@
{
key: localize('general.storageDepositPerNft'),
value:
quantity > 1 ? formatTokenAmountPrecise(storageDeposit, getBaseToken()) : undefined,
quantity > 1
? formatTokenAmountBestMatch(storageDeposit, getBaseToken())
: undefined,
},
{
key: localize('general.totalStorageDeposit'),
value:
quantity > 1
? formatTokenAmountPrecise(totalStorageDeposit, getBaseToken())
? formatTokenAmountBestMatch(totalStorageDeposit, getBaseToken())
: undefined,
},
{
key: localize('general.storageDeposit'),
value:
quantity === 1
? formatTokenAmountPrecise(storageDeposit, getBaseToken())
? formatTokenAmountBestMatch(storageDeposit, getBaseToken())
: undefined,
},
{
Expand Down
3 changes: 0 additions & 3 deletions packages/desktop/features/network.features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ const networkFeatures: INetworkFeatures = {
enabled: false,
},
},
evmNetworks: {
enabled: false,
},
}

export default networkFeatures
24 changes: 24 additions & 0 deletions packages/desktop/features/onboarding.features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const onboardingFeaturesForIota: IOnboardingFeaturesForNetwork = {
enabled: false,
},
},
defaultIscChains: {
enabled: false,
},
defaultEvmChains: {
enabled: false,
},
}

const onboardingFeaturesForShimmer: IOnboardingFeaturesForNetwork = {
Expand Down Expand Up @@ -82,6 +88,12 @@ const onboardingFeaturesForShimmer: IOnboardingFeaturesForNetwork = {
enabled: true,
},
},
defaultIscChains: {
enabled: true,
},
defaultEvmChains: {
enabled: false,
},
}

const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = {
Expand Down Expand Up @@ -123,6 +135,12 @@ const onboardingFeaturesForTestnet: IOnboardingFeaturesForNetwork = {
enabled: true,
},
},
defaultIscChains: {
enabled: true,
},
defaultEvmChains: {
enabled: true,
},
}

const onboardingFeaturesForCustom: IOnboardingFeaturesForNetwork = {
Expand Down Expand Up @@ -164,6 +182,12 @@ const onboardingFeaturesForCustom: IOnboardingFeaturesForNetwork = {
enabled: true,
},
},
defaultIscChains: {
enabled: false,
},
defaultEvmChains: {
enabled: false,
},
}

const onboardingFeatures: OnboardingFeatures = {
Expand Down
100 changes: 66 additions & 34 deletions packages/desktop/lib/electron/managers/auto-update.manager.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,74 @@
import { ipcMain } from 'electron'
import { autoUpdater, CancellationToken, UpdateInfo, ProgressInfo } from 'electron-updater'
import { app, ipcMain } from 'electron'
import * as electronLog from 'electron-log'
import { getOrInitWindow, updateAppVersionDetails } from '../processes/main.process'
import { CancellationToken, ProgressInfo, UpdateInfo, autoUpdater } from 'electron-updater'

interface VersionDetails {
interface IVersionDetails {
upToDate: boolean
newVersion: string
newVersionReleaseDate: Date
currentVersion: string
newVersion?: string
newVersionReleaseDate?: Date
changelog: string
}

export default class AutoUpdateManager {
export default class AutoUpdateManager implements IVersionDetails {
private window: Electron.BrowserWindow
private downloadCancellation?: CancellationToken

constructor() {
public upToDate: boolean = true
public currentVersion: string
public newVersion?: string
public newVersionReleaseDate?: Date
public changelog: string = ''

constructor(window: Electron.BrowserWindow) {
this.window = window
this.currentVersion = app.getVersion()
this.init()
}

private init(): void {
this.removeHandlers()
ipcMain.handle('update-download', this.updateDownload.bind(this))
ipcMain.handle('update-cancel', this.updateCancel.bind(this))
ipcMain.handle('update-install', this.updateInstall.bind(this))
ipcMain.handle('update-check', this.updateCheck.bind(this))

autoUpdater.logger = electronLog
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-expect-error
autoUpdater.logger.transports.file.level = 'info'
autoUpdater.autoDownload = false

autoUpdater.removeAllListeners()
autoUpdater.on('update-available', this.handleUpdateAvailable.bind(this))
autoUpdater.on('download-progress', this.handleDownloadProgress.bind(this))
autoUpdater.on('update-downloaded', this.handleUpdateDownloaded.bind(this))
autoUpdater.on('error', this.handleError.bind(this))

void this.updateCheck()

ipcMain.handle('get-version-details', this.getVersionDetails.bind(this))

if (app.isPackaged) {
ipcMain.handle('update-download', this.updateDownload.bind(this))
ipcMain.handle('update-cancel', this.updateCancel.bind(this))
ipcMain.handle('update-install', this.updateInstall.bind(this))
ipcMain.handle('update-check', this.updateCheck.bind(this))

autoUpdater.logger = electronLog
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-expect-error
autoUpdater.logger.transports.file.level = 'info'
autoUpdater.autoDownload = false

autoUpdater.removeAllListeners()
autoUpdater.on('update-available', this.handleUpdateAvailable.bind(this))
autoUpdater.on('download-progress', this.handleDownloadProgress.bind(this))
autoUpdater.on('update-downloaded', this.handleUpdateDownloaded.bind(this))
autoUpdater.on('error', this.handleError.bind(this))

void this.updateCheck()
}
}

public getVersionDetails(): IVersionDetails {
return {
upToDate: this.upToDate,
currentVersion: this.currentVersion,
newVersion: this.newVersion,
newVersionReleaseDate: this.newVersionReleaseDate,
changelog: this.changelog,
}
}

private updateAppVersionDetails(versionDetails: Partial<IVersionDetails>): void {
this.upToDate = versionDetails.upToDate ?? this.upToDate
this.newVersion = versionDetails.newVersion ?? this.newVersion
this.newVersionReleaseDate = versionDetails.newVersionReleaseDate ?? this.newVersionReleaseDate
this.changelog = versionDetails.changelog ?? this.changelog

this.window?.webContents.send('version-details', this.getVersionDetails())
}

private handleUpdateAvailable(info: UpdateInfo): void {
Expand All @@ -45,27 +77,26 @@ export default class AutoUpdateManager {
if (typeof releaseNotes === 'string') {
releaseNotes = releaseNotes.replace(/<[^>]*>?/gm, '')
}
const versionDetails: VersionDetails = {

this.updateAppVersionDetails({
upToDate: false,
newVersion: info.version,
newVersionReleaseDate: new Date(info.releaseDate),
changelog: releaseNotes.toString(),
}

updateAppVersionDetails(versionDetails)
})
}

private handleDownloadProgress(progressObj: ProgressInfo): void {
getOrInitWindow('main').webContents.send('version-progress', progressObj)
this.window?.webContents.send('version-progress', progressObj)
}

private handleUpdateDownloaded(info: UpdateInfo): void {
getOrInitWindow('main').webContents.send('version-complete', info)
this.window?.webContents.send('version-complete', info)
}

private handleError(err: Error): void {
this.downloadCancellation = undefined
getOrInitWindow('main').webContents.send('version-error', err)
this.window?.webContents.send('version-error', err)
}

private updateDownload(): void {
Expand Down Expand Up @@ -99,5 +130,6 @@ export default class AutoUpdateManager {
ipcMain.removeHandler('update-cancel')
ipcMain.removeHandler('update-install')
ipcMain.removeHandler('update-check')
ipcMain.removeHandler('get-version-details')
}
}
33 changes: 9 additions & 24 deletions packages/desktop/lib/electron/processes/main.process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ import features from '@features/features'

import { LedgerApiMethod } from '@core/ledger/enums'

import { ITransakWindowData } from '@core/app/interfaces'
import { DEFAULT_WEB_PREFERENCES } from '../constants/default-web-preferences.constant'
import { windows } from '../constants/windows.constant'
import { IElectronSettings, IWindowState } from '../interfaces'
import type { ILedgerProcessMessage } from '../interfaces/ledger-process-message.interface'
import { registerPowerMonitorListeners } from '../listeners'
import AutoUpdateManager from '../managers/auto-update.manager'
import { ElectronSettingsManager } from '../managers/electron-settings.manager'
import KeychainManager from '../managers/keychain.manager'
import NftDownloadManager from '../managers/nft-download.manager'
import ThirdPartyAppManager from '../managers/third-party-profiles.manager'
import TransakManager from '../managers/transak.manager'
import { contextMenu } from '../menus/context.menu'
import { initMenu } from '../menus/menu'
Expand All @@ -32,12 +38,6 @@ import { getDiagnostics } from '../utils/diagnostics.utils'
import { shouldReportError } from '../utils/error.utils'
import { ensureDirectoryExistence } from '../utils/file-system.utils'
import { getMachineId } from '../utils/os.utils'
import { registerPowerMonitorListeners } from '../listeners'
import ThirdPartyAppManager from '../managers/third-party-profiles.manager'
import { ITransakWindowData } from '@core/app/interfaces'
import { ElectronSettingsManager } from '../managers/electron-settings.manager'
import { IElectronSettings, IWindowState } from '../interfaces'
import { DEFAULT_WEB_PREFERENCES } from '../constants/default-web-preferences.constant'
import { AboutWindow } from '../windows/about.window'

export let appIsReady = false
Expand Down Expand Up @@ -118,14 +118,6 @@ const paths = {
ledger: '',
}

let versionDetails = {
upToDate: true,
currentVersion: app.getVersion(),
newVersion: '',
newVersionReleaseDate: new Date(),
changelog: '',
}

if (app.isPackaged) {
paths.html = path.join(app.getAppPath(), '/public/index.html')
paths.preload = path.join(app.getAppPath(), '/public/build/preload.js')
Expand Down Expand Up @@ -162,6 +154,7 @@ function tryOpenExternalUrl(e: Event, url: string): void {
}
}

let autoUpdateManager: AutoUpdateManager
export function createMainWindow(): BrowserWindow {
const mainWindowState = windowStateKeeper('main')

Expand Down Expand Up @@ -198,12 +191,11 @@ export function createMainWindow(): BrowserWindow {

void windows.main.loadURL('http://localhost:8080')
} else {
new AutoUpdateManager()

// load the index.html of the app.
void windows.main.loadFile(paths.html)
}

autoUpdateManager = new AutoUpdateManager(windows.main)
new NftDownloadManager()
new ThirdPartyAppManager()

Expand Down Expand Up @@ -239,7 +231,7 @@ export function createMainWindow(): BrowserWindow {
})

windows.main.webContents.on('did-finish-load', () => {
windows.main?.webContents?.send?.('version-details', versionDetails)
windows.main?.webContents?.send?.('version-details', autoUpdateManager.getVersionDetails())
})

/**
Expand Down Expand Up @@ -427,7 +419,6 @@ ipcMain.handle('get-path', (_e, path) => {
}
return app.getPath(path)
})
ipcMain.handle('get-version-details', () => versionDetails)
ipcMain.handle('focus-window', () => {
if (windows.main) {
if (windows.main.isMinimized()) {
Expand Down Expand Up @@ -627,9 +618,3 @@ function windowStateKeeper(windowName: string): IWindowState {
track,
}
}

export function updateAppVersionDetails(details: object): void {
versionDetails = Object.assign({}, versionDetails, details)

getOrInitWindow('main').webContents.send('version-details', versionDetails)
}
Loading

0 comments on commit 8a1a415

Please sign in to comment.