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

refactor: remove routing logic for core modules #5146

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
a1843d9
chore: remove sidebar file
maxwellmattryan Nov 4, 2022
a3c13be
chore: remove router dependencies for deleting an account:
maxwellmattryan Nov 4, 2022
5715fc1
Merge branch 'stardust-develop' into refactor/remove-routing-logic-fo…
maxwellmattryan Nov 7, 2022
953fa00
Merge branch 'stardust-develop' into refactor/remove-routing-logic-fo…
maxwellmattryan Nov 7, 2022
f23e515
chore: fix logout
maxwellmattryan Nov 9, 2022
185cf49
chore: fix wallet route reset
maxwellmattryan Nov 9, 2022
b51a732
chore: fix login
maxwellmattryan Nov 9, 2022
9e49b67
chore: cleanup code more
maxwellmattryan Nov 9, 2022
8f00db6
chore: remove last hard dep from core modules
maxwellmattryan Nov 9, 2022
55d2865
Merge branch 'stardust-develop' into refactor/remove-routing-logic-fo…
maxwellmattryan Nov 9, 2022
4cb7b1b
Merge branch 'stardust-develop' into refactor/remove-routing-logic-fo…
maxwellmattryan Nov 10, 2022
d04691a
chore: adjust code per PR review comments
maxwellmattryan Nov 10, 2022
50e03b3
chore: create router manageR
maxwellmattryan Nov 10, 2022
cb5a06f
chore: cleanup some more code
maxwellmattryan Nov 10, 2022
742b3ec
Merge branch 'stardust-develop' into refactor/remove-routing-logic-fo…
maxwellmattryan Nov 10, 2022
de9a207
chore: cleanup code more
maxwellmattryan Nov 11, 2022
97b737e
Merge branch 'stardust-develop' into refactor/remove-routing-logic-fo…
Tuditi Nov 11, 2022
6850817
Merge branch 'stardust-develop' into refactor/remove-routing-logic-fo…
maxwellmattryan Nov 11, 2022
daf7cc9
chore: cleanup code some more
maxwellmattryan Nov 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 31 additions & 17 deletions packages/desktop/App.svelte
Expand Up @@ -12,15 +12,24 @@
onboardingRoute,
openSettings,
} from '@core/router'
import { appSettings, appStage, AppStage, appVersionDetails, initAppSettings, setPlatform } from '@core/app'
import {
appSettings,
appStage,
AppStage,
appVersionDetails,
extendPlatform,
initAppSettings,
Platform,
setPlatform,
} from '@core/app'
import { showAppNotification } from '@auxiliary/notification'
import { closePopup, openPopup, popupState } from '@auxiliary/popup'
import { initialiseOnboardingFlow } from '@contexts/onboarding'
import { NetworkProtocol, NetworkType } from '@core/network'
import { Electron } from './lib/electron'
import { getLocalisedMenuItems } from './lib/helpers'
import { Popup, Route, TitleBar, ToastContainer, Transition } from '@ui'
import { Dashboard, LoginRouter, OnboardingRouter, Settings, Splash } from '@views'
import { getRouterForAppContext, resetRouterForAppContext, resetRouters } from './lib/routers'

appStage.set(AppStage[process.env.STAGE.toUpperCase()] ?? AppStage.ALPHA)

Expand All @@ -29,7 +38,7 @@
checkAndMigrateProfiles()

async function handleCrashReporting(sendCrashReports: boolean): Promise<void> {
await Electron.updateAppSettings({ sendCrashReports })
await Platform.updateAppSettings({ sendCrashReports })
}

$: void handleCrashReporting($appSettings.sendCrashReports)
Expand All @@ -39,11 +48,11 @@

$: {
if ($isLocaleLoaded) {
Electron.updateMenu('strings', getLocalisedMenuItems($_ as Locale))
Platform.updateMenu('strings', getLocalisedMenuItems($_ as Locale))
}
}

$: Electron.updateMenu(
$: Platform.updateMenu(
'canCreateNewProfile',
$appRoute === AppRoute.Login ||
($appRoute === AppRoute.Onboarding &&
Expand Down Expand Up @@ -77,57 +86,62 @@
// await setAppVersionDetails()
// pollCheckForAppUpdate()
// }
Electron.onEvent('menu-navigate-wallet', () => {
Platform.onEvent('menu-navigate-wallet', () => {
$dashboardRouter.goTo(DashboardRoute.Wallet)
})
Electron.onEvent('menu-navigate-settings', () => {
Platform.onEvent('menu-navigate-settings', () => {
if ($loggedIn) {
closePopup()
openSettings()
} else {
settings = true
}
})
Electron.onEvent('menu-check-for-update', () => {
Platform.onEvent('menu-check-for-update', () => {
openPopup({
type: 'version',
props: {
currentVersion: $appVersionDetails.currentVersion,
},
})
})
Electron.onEvent('menu-error-log', () => {
Platform.onEvent('menu-error-log', () => {
openPopup({ type: 'errorLog' })
})
Electron.onEvent('menu-diagnostics', () => {
Platform.onEvent('menu-diagnostics', () => {
openPopup({ type: 'diagnostics' })
})
Electron.onEvent('menu-create-developer-profile', () => {
Platform.onEvent('menu-create-developer-profile', () => {
void initialiseOnboardingFlow({
isDeveloperProfile: true,
networkProtocol: NetworkProtocol.Shimmer,
})
})
Electron.onEvent('menu-create-normal-profile', () => {
Platform.onEvent('menu-create-normal-profile', () => {
void initialiseOnboardingFlow({
isDeveloperProfile: false,
networkProtocol: NetworkProtocol.Shimmer,
networkType: NetworkType.Mainnet,
})
})

Electron.onEvent('deep-link-request', showDeepLinkNotification)
Platform.onEvent('deep-link-request', showDeepLinkNotification)

extendPlatform([
['getRouterForAppContext', getRouterForAppContext],
['resetRouterForAppContext', resetRouterForAppContext],
['resetRouters', resetRouters],
])

await cleanupEmptyProfiles()
// loadPersistedProfileIntoActiveProfile($activeProfileId)

const platform = await Electron.getOS()
const platform = await Platform.getOS()
setPlatform(platform)
})

onDestroy(() => {
Electron.removeListenersForEvent('deep-link-request')
Electron.DeepLinkManager.clearDeepLinkRequest()
Platform.removeListenersForEvent('deep-link-request')
Platform.DeepLinkManager.clearDeepLinkRequest()
})

function showDeepLinkNotification(): void {
Expand Down
5 changes: 3 additions & 2 deletions packages/desktop/components/SidebarTab.svelte
@@ -1,8 +1,9 @@
<script lang="typescript">
import { Icon, Text, Tooltip, PingingBadge } from '@ui'
import { SidebarTab, dashboardRoute } from '@core/router'
import { dashboardRoute } from '@core/router'
import { ISidebarTab } from '../lib/routers'

export let tab: SidebarTab = undefined
export let tab: ISidebarTab = undefined

let tooltipAnchor: HTMLButtonElement
let showTooltip = false
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop/lib/routers/actions/index.ts
@@ -0,0 +1,2 @@
export * from './resetRouterForAppContext'
export * from './resetRouters'
17 changes: 17 additions & 0 deletions packages/desktop/lib/routers/actions/resetRouterForAppContext.ts
@@ -0,0 +1,17 @@
import { get } from 'svelte/store'
import { AppContext } from '@core/app/enums'
import { dashboardRouter } from '@core/router/routers'

export function resetRouterForAppContext(context: AppContext): void {
get(dashboardRouter).reset()
switch (context) {
case AppContext.Dashboard:
get(dashboardRouter).reset()
break
case AppContext.Login:
get(dashboardRouter).reset()
break
default:
break
}
maxwellmattryan marked this conversation as resolved.
Show resolved Hide resolved
}
44 changes: 44 additions & 0 deletions packages/desktop/lib/routers/actions/resetRouters.ts
@@ -0,0 +1,44 @@
import { get } from 'svelte/store'
import {
appRouter,
appSetupRouter,
collectiblesRouter,
dashboardRouter,
ledgerSetupRouter,
loginRouter,
networkSetupRouter,
onboardingRouter,
profileBackupRouter,
profileRecoveryRouter,
profileSetupRouter,
settingsRouter,
shimmerClaimingRouter,
storageProtectionSetupRouter,
strongholdSetupRouter,
} from '@core/router'

export function resetRouters(): void {
resetSubrouters()
resetBaseRouters()
}

function resetSubrouters(): void {
get(appSetupRouter).reset()
get(loginRouter).reset()
get(ledgerSetupRouter).reset()
get(networkSetupRouter).reset()
get(strongholdSetupRouter).reset()
get(profileBackupRouter).reset()
get(profileRecoveryRouter).reset()
get(profileSetupRouter).reset()
get(storageProtectionSetupRouter).reset()
get(shimmerClaimingRouter).reset()
}

function resetBaseRouters(): void {
get(appRouter).reset()
get(dashboardRouter).reset()
get(onboardingRouter).reset()
get(settingsRouter).reset()
get(collectiblesRouter).reset()
}
3 changes: 3 additions & 0 deletions packages/desktop/lib/routers/index.ts
@@ -0,0 +1,3 @@
export * from './actions'
export * from './interfaces'
export * from './utils'
1 change: 1 addition & 0 deletions packages/desktop/lib/routers/interfaces/index.ts
@@ -0,0 +1 @@
export * from './sidebar-tab.interface'
@@ -1,7 +1,7 @@
import { DashboardRoute } from '@core/router'
import { NotificationType } from '@auxiliary/notification'

export type SidebarTab = {
export interface ISidebarTab {
icon: string
label: string
route: DashboardRoute
Expand Down
14 changes: 14 additions & 0 deletions packages/desktop/lib/routers/utils/getRouterForAppContext.ts
@@ -0,0 +1,14 @@
import { get } from 'svelte/store'

import { AppContext } from '@core/app/enums'
import { IRouter } from '@core/router/interfaces'
import { loginRouter } from '@core/router/subrouters'

export function getRouterForAppContext(context: AppContext): IRouter {
switch (context) {
case AppContext.Login:
return get(loginRouter)
default:
return undefined
}
}
1 change: 1 addition & 0 deletions packages/desktop/lib/routers/utils/index.ts
@@ -0,0 +1 @@
export * from './getRouterForAppContext'
21 changes: 7 additions & 14 deletions packages/desktop/views/dashboard/Sidebar.svelte
@@ -1,21 +1,14 @@
<script lang="typescript">
import { Drawer, Icon, ProfileActionsModal, Text, Modal, NetworkIndicator, NotificationBadge } from '@ui'
import { Drawer, Icon, Modal, NetworkIndicator, NotificationBadge, ProfileActionsModal, Text } from '@ui'
import { SidebarTab } from '@components'
import { Settings } from './settings'
import features from '@features/features'
import { appVersionDetails, mobile } from '@core/app'
import { AppContext, appVersionDetails, mobile, Platform } from '@core/app'
import { getInitials, isRecentDate } from '@core/utils'
import { activeProfile } from '@core/profile'
import {
dashboardRouter,
DashboardRoute,
resetWalletRoute,
settingsRoute,
settingsRouter,
SettingsRoute,
SidebarTab as SidebarTabType,
} from '@core/router'
import { activeProfile } from '@core/profile/stores'
import { DashboardRoute, dashboardRouter, settingsRoute, SettingsRoute, settingsRouter } from '@core/router'
import { localize } from '@core/i18n'
import { ISidebarTab } from '../../lib/routers'

let profileModal: Modal
let drawer: Drawer
Expand All @@ -30,7 +23,7 @@
$: lastBackupDate = lastStrongholdBackupTime ? new Date(lastStrongholdBackupTime) : null
$: isBackupSafe = lastBackupDate && isRecentDate(lastBackupDate)?.lessThanThreeMonths

const sidebarTabs: SidebarTabType[] = [
const sidebarTabs: ISidebarTab[] = [
...(features?.wallet?.enabled
? [
{
Expand Down Expand Up @@ -64,7 +57,7 @@
]

function openWallet(): void {
resetWalletRoute()
Platform.resetRouterForAppContext(AppContext.Dashboard)
maxwellmattryan marked this conversation as resolved.
Show resolved Hide resolved
}

function openCollectibles(): void {
Expand Down
19 changes: 13 additions & 6 deletions packages/shared/components/modals/AccountActionsMenu.svelte
@@ -1,11 +1,14 @@
<script lang="typescript">
import { selectedAccount } from '@core/account'
import { Platform } from '@core/app/classes'
import { selectedAccount, setSelectedAccount } from '@core/account'
import { localize } from '@core/i18n'
import { activeAccounts, visibleActiveAccounts } from '@core/profile'
import { deleteAccount } from '@core/profile-manager'
import { Icon } from '@lib/auxiliary/icon'
import { openPopup } from '@auxiliary/popup'
import { activeAccounts, visibleActiveAccounts } from '@core/profile/stores'
import { deleteAccount } from '@core/profile-manager/actions'
import { Icon } from '@lib/auxiliary/icon/enums'
import { openPopup } from '@auxiliary/popup/actions'
import { HR, MenuItem, Modal, ToggleHiddenAccountMenuItem } from 'shared/components'
import { get } from 'svelte/store'
import { AppContext } from '@core/app/enums'

export let modal: Modal = undefined

Expand All @@ -27,7 +30,11 @@
type: 'deleteAccount',
props: {
account: selectedAccount,
deleteAccount,
deleteAccount: async (index: number) => {
await deleteAccount(index)
setSelectedAccount(get(visibleActiveAccounts)?.[0]?.index ?? null)
Platform.resetRouterForAppContext(AppContext.Dashboard)
maxwellmattryan marked this conversation as resolved.
Show resolved Hide resolved
},
},
})
modal.close()
Expand Down
15 changes: 14 additions & 1 deletion packages/shared/lib/core/app/classes/platform.class.ts
Expand Up @@ -2,8 +2,21 @@ import { get } from 'svelte/store'

import { IPlatform } from '../interfaces'
import { mobile } from '../stores'
import { PlatformExtension } from '../types'

const IS_MOBILE = get(mobile)

// TODO: https://github.com/iotaledger/firefly/issues/5143
export const Platform: IPlatform = window[IS_MOBILE ? '__CAPACITOR__' : '__ELECTRON__']
export let Platform: IPlatform = window[IS_MOBILE ? '__CAPACITOR__' : '__ELECTRON__']

export function extendPlatform(extensions: PlatformExtension[]): void {
maxwellmattryan marked this conversation as resolved.
Show resolved Hide resolved
const extensionBoundObject = Object.fromEntries(extensions)
Platform = {
/**
* CAUTION: Normally the order of these spread operations would be reversed,
* but this ensures that important methods cannot be overridden.
maxwellmattryan marked this conversation as resolved.
Show resolved Hide resolved
*/
...extensionBoundObject,
...Platform,
}
}
6 changes: 6 additions & 0 deletions packages/shared/lib/core/app/enums/app-context.enum.ts
@@ -0,0 +1,6 @@
export enum AppContext {
Login = 'login',
Dashboard = 'dashboard',
Settings = 'settings',
Onboarding = 'wallet',
}
1 change: 1 addition & 0 deletions packages/shared/lib/core/app/enums/index.ts
@@ -1,3 +1,4 @@
export * from './app-context.enum'
export * from './app-stage.enum'
export * from './app-theme.enum'
export * from './platform-option.enum'
1 change: 1 addition & 0 deletions packages/shared/lib/core/app/index.ts
Expand Up @@ -4,4 +4,5 @@ export * from './classes'
export * from './enums'
export * from './interfaces'
export * from './stores'
export * from './types'
export * from './utils'
@@ -1,11 +1,8 @@
import { DashboardRoute } from '@core/router'

import { IAppUpdateDownloadProgress } from './app-update-download-progress.interface'
import { IAppVersionDetails } from './app-version-details.interface'

export interface IPlatformEventMap {
'menu-logout': void
'menu-navigate-wallet': DashboardRoute
maxwellmattryan marked this conversation as resolved.
Show resolved Hide resolved
'menu-navigate-settings': void
'menu-check-for-update': void
'menu-error-log': void
Expand Down
11 changes: 9 additions & 2 deletions packages/shared/lib/core/app/interfaces/platform.interface.ts
@@ -1,4 +1,7 @@
import { IError } from '@core/error'
import { IError } from '@core/error/interfaces'
import { IRouter } from '@core/router/interfaces'

import { AppContext } from '../enums'

import { IDeepLinkManager, INotificationManager, IPincodeManager } from './managers'
import { IAppSettings } from './app-settings.interface'
Expand All @@ -10,7 +13,7 @@ export interface IPlatform {
exportTransactionHistory(defaultPath: string, contents: string): Promise<string | null>
getUserDataPath(): Promise<string>
getDiagnostics(): Promise<{ label: string; value: string }[]>
getOS(): Promise<string> | string
getOS(): Promise<string>
getMachineId(): Promise<string>
updateAppSettings(settings: Partial<IAppSettings>): Promise<void>
getActiveProfile(): string
Expand Down Expand Up @@ -41,6 +44,10 @@ export interface IPlatform {

unhandledException(title: string, err: IError | unknown): Promise<void>

resetRouters?(): void
resetRouterForAppContext?(context: AppContext): void
getRouterForAppContext?(context: AppContext): IRouter

onEvent<K extends keyof IPlatformEventMap>(eventName: K, callback: (param: IPlatformEventMap[K]) => void)
removeListenersForEvent<K extends keyof IPlatformEventMap>(eventName: K)
}
1 change: 1 addition & 0 deletions packages/shared/lib/core/app/types/index.ts
@@ -0,0 +1 @@
export * from './platform-extension.type'
@@ -0,0 +1 @@
export type PlatformExtension = [string, (..._: unknown[]) => unknown]