Skip to content

Commit

Permalink
Merge branch 'develop' into 2376-icon
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuditi authored Apr 28, 2024
2 parents caf244e + 0bc3f5a commit 0960f87
Show file tree
Hide file tree
Showing 41 changed files with 483 additions and 244 deletions.
52 changes: 26 additions & 26 deletions firefly.diff

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions packages/desktop/features/collectibles.features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const collectiblesFeatures: ICollectiblesFeatures = {
erc721: {
enabled: true,
},
collections: {
enabled: false,
},
}

export default collectiblesFeatures
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { IWindowState } from './window-state.interface'

export interface IElectronSettings {
windowState: IWindowState
}
2 changes: 2 additions & 0 deletions packages/desktop/lib/electron/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './electron-settings.interface'
export * from './window-state.interface'
11 changes: 11 additions & 0 deletions packages/desktop/lib/electron/interfaces/window-state.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { BrowserWindow } from 'electron'

export interface IWindowState {
x?: number
y?: number
width: number
height: number
isMaximized?: boolean

track?(window: BrowserWindow): void
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { JsonFileManager } from './json-file.manager'
import { IElectronSettings } from '../interfaces'

const SETTINGS_FILE_NAME = 'settings.json'

export class ElectronSettingsManager {
public static saveSettings(settings: IElectronSettings): void {
JsonFileManager.saveJsonToFile(SETTINGS_FILE_NAME, settings)
}

public static loadSettings(): IElectronSettings {
const settings = JsonFileManager.loadJsonFromFile(SETTINGS_FILE_NAME) as IElectronSettings | undefined
return settings ? settings : { windowState: { width: 800, height: 600 } }
}

public static updateSettings(settings: IElectronSettings): void {
const config = ElectronSettingsManager.loadSettings()
ElectronSettingsManager.saveSettings({ ...config, ...settings })
}
}
29 changes: 29 additions & 0 deletions packages/desktop/lib/electron/managers/json-file.manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { IError } from '@core/error/interfaces'
import { app } from 'electron'
import fs from 'fs'
import path from 'path'

export class JsonFileManager {
public static saveJsonToFile(filename: string, data: object): void {
try {
fs.writeFileSync(JsonFileManager.getFilePath(filename), JSON.stringify(data))
} catch (err) {
console.error(err)
}
}

public static loadJsonFromFile(filename: string): object | undefined {
try {
return JSON.parse(fs.readFileSync(JsonFileManager.getFilePath(filename)).toString())
} catch (err) {
if (!(err as IError).message?.includes('ENOENT')) {
console.error(err)
}
}
}

private static getFilePath(filename: string): string {
const userDataPath = app.getPath('userData')
return path.join(userDataPath, filename)
}
}
74 changes: 13 additions & 61 deletions packages/desktop/lib/electron/processes/main.process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ 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 { IError } from '@core/error'
import { ElectronSettingsManager } from '../managers/electron-settings.manager'
import { IElectronSettings, IWindowState } from '../interfaces'

export let appIsReady = false

Expand Down Expand Up @@ -179,7 +180,7 @@ function tryOpenExternalUrl(e: Event, url: string): void {
}

export function createMainWindow(): BrowserWindow {
const mainWindowState = windowStateKeeper('main', 'settings.json')
const mainWindowState = windowStateKeeper('main')

// Create the browser window
windows.main = new BrowserWindow({
Expand All @@ -206,7 +207,7 @@ export function createMainWindow(): BrowserWindow {
windows.main.maximize()
}

mainWindowState.track(windows.main)
mainWindowState.track?.(windows.main)

if (!app.isPackaged) {
// Enable dev tools only in developer mode
Expand Down Expand Up @@ -490,7 +491,7 @@ ipcMain.handle('handle-error', (_e, errorType, error) => {
ipcMain.handle('get-machine-id', () => getMachineId())

// Settings
ipcMain.handle('update-app-settings', (_e, settings) => updateSettings(settings))
ipcMain.handle('update-app-settings', (_e, settings) => ElectronSettingsManager.updateSettings(settings))

// Theme
nativeTheme.on('updated', () => {
Expand Down Expand Up @@ -642,17 +643,17 @@ export function closeErrorWindow(): void {
}
}

function windowStateKeeper(windowName: string, settingsFilename: string): IAppState {
function windowStateKeeper(windowName: string): IWindowState {
let window: BrowserWindow
let windowState = <IAppState>{
let windowState = <IWindowState>{
x: 0,
y: 0,
width: 1280,
height: process.platform === 'win32' ? 720 + 28 : 720,
}

function setBounds(): void {
const settings = <ISettings>loadJsonConfig(settingsFilename)
const settings = ElectronSettingsManager.loadSettings()

if (settings && settings.windowState && settings.windowState[windowName]) {
windowState = settings.windowState[windowName]
Expand All @@ -663,16 +664,16 @@ function windowStateKeeper(windowName: string, settingsFilename: string): IAppSt
function saveState(): void {
windowState.isMaximized = window.isMaximized()
if (!windowState.isMaximized) {
windowState = window.getBounds() as IAppState
windowState = window.getBounds() as IWindowState
}

let settings = loadJsonConfig(settingsFilename) as ISettings
let settings = ElectronSettingsManager.loadSettings()

settings = settings || <ISettings>{}
settings.windowState = settings.windowState || <IAppState>{}
settings = settings || <IElectronSettings>{}
settings.windowState = settings.windowState || <IWindowState>{}
settings.windowState[windowName] = windowState

saveJsonConfig(settingsFilename, settings)
ElectronSettingsManager.saveSettings(settings)
}

function track(win: BrowserWindow): void {
Expand All @@ -696,55 +697,6 @@ function windowStateKeeper(windowName: string, settingsFilename: string): IAppSt
}
}

interface ISettings {
windowState: IAppState
}

interface IAppState {
x: number
y: number
width: number
height: number
isMaximized: boolean

track(window: BrowserWindow): void
}

function updateSettings(data: object): void {
const filename = 'settings.json'
const config = loadJsonConfig(filename)

/**
* CAUTION: We must be careful saving properties to this file, as
* once we decide to save it there then it will be there forever
* even if the name changes later.
*/
saveJsonConfig(filename, { ...config, ...data })
}

function saveJsonConfig(filename: string, data: object): void {
try {
fs.writeFileSync(getJsonConfig(filename), JSON.stringify(data))
} catch (err) {
console.error(err)
}
}

function loadJsonConfig(filename: string): object | undefined {
try {
return JSON.parse(fs.readFileSync(getJsonConfig(filename)).toString())
} catch (err) {
if (!(err as IError).message?.includes('ENOENT')) {
console.error(err)
}
}
}

function getJsonConfig(filename: string): string {
const userDataPath = app.getPath('userData')
return path.join(userDataPath, filename)
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import features from '@features/features'
import { selectedAccountIndex } from '@core/account/stores'
import { collectiblesRoute, CollectiblesRoute, collectiblesRouter } from '@core/router'
import { CollectiblesDetailsView, CollectiblesGalleryView } from './views'
import { CollectiblesDetailsView, CollectiblesGalleryView, CollectionsGalleryView } from './views'
import { selectedCollectiblesTab } from '@core/nfts/stores'
$: $selectedAccountIndex !== undefined && $collectiblesRouter.reset()
Expand All @@ -14,7 +15,11 @@

<div class="w-full h-full flex flex-col flex-nowrap p-8 relative flex-1">
{#if $collectiblesRoute === CollectiblesRoute.Gallery}
<CollectiblesGalleryView />
{#if $selectedCollectiblesTab?.key === 'collectibles'}
<CollectiblesGalleryView />
{:else if $selectedCollectiblesTab?.key === 'collections'}
<CollectionsGalleryView />
{/if}
{/if}
{#if $collectiblesRoute === CollectiblesRoute.Details}
<CollectiblesDetailsView />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<script lang="ts">
import { Tabs } from '@bloomwalletio/ui'
import { COLLECTIBLES_TABS } from '@core/nfts'
import { selectedCollectiblesTab } from '@core/nfts/stores'
const selectedIndex = COLLECTIBLES_TABS.findIndex((tab) => tab.key === $selectedCollectiblesTab?.key)
</script>

{#if COLLECTIBLES_TABS.length > 1}
<div class="w-64">
<Tabs {selectedIndex} bind:selectedTab={$selectedCollectiblesTab} tabs={COLLECTIBLES_TABS} />
</div>
{/if}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as Irc27CollectibleDetails } from './Irc27CollectibleDetails.svelte'
export { default as CollectiblesTabs } from './CollectiblesTabs.svelte'
export { default as Erc721CollectibleDetails } from './Erc721CollectibleDetails.svelte'
export { default as Irc27CollectibleDetails } from './Irc27CollectibleDetails.svelte'
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<script lang="ts">
import { localize } from '@core/i18n'
import { nftFilter, nftSearchTerm, ownedNfts } from '@core/nfts/stores'
import { NftGallery, SearchInput } from '@ui'
import { Button, IconName, Text, Pill } from '@bloomwalletio/ui'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import features from '@features/features'
import { Button, IconName, Pill, Text } from '@bloomwalletio/ui'
import { CollectiblesListMenu, EmptyListPlaceholder } from '@components'
import { Filter } from '@components/filter'
import { localize } from '@core/i18n'
import { Nft } from '@core/nfts/interfaces'
import { nftFilter, nftSearchTerm, ownedNfts } from '@core/nfts/stores'
import { isVisibleNft } from '@core/nfts/utils'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import features from '@features/features'
import { NftGallery, SearchInput } from '@ui'
import { CollectiblesTabs } from '../components'
let queriedNfts: Nft[] = []
$: $nftSearchTerm,
Expand All @@ -24,15 +25,16 @@
}
</script>

<collectibles-gallery-view>
<div class="flex flex-row justify-between">
<div class="flex flex-row text-left gap-2 items-center">
<collectibles-gallery-view class="flex flex-col w-full h-full gap-4">
<header class="flex flex-row items-center justify-between">
<div class="flex flex-row text-left gap-2 items-center flex-1">
<Text type="h6">{localize('views.collectibles.gallery.title')}</Text>
<Pill color="neutral">
<Text textColor="secondary">{String(queriedNfts.length ?? '')}</Text>
</Pill>
</div>
<div class="flex items-center gap-5 h-10 shrink-0">
<CollectiblesTabs />
<div class="flex justify-end items-center gap-5 h-10 shrink-0 flex-1">
{#if $ownedNfts.length}
<SearchInput bind:value={$nftSearchTerm} />
<Filter filterStore={nftFilter} />
Expand All @@ -41,7 +43,7 @@
<CollectiblesListMenu />
{/if}
</div>
</div>
</header>
{#if $ownedNfts.length}
{#if queriedNfts.length}
<NftGallery nfts={queriedNfts} />
Expand All @@ -61,9 +63,3 @@
</div>
{/if}
</collectibles-gallery-view>

<style lang="postcss">
collectibles-gallery-view {
@apply flex flex-col w-full h-full gap-4;
}
</style>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<script lang="ts">
import { Button, IconName, Pill, Text } from '@bloomwalletio/ui'
import { CollectiblesListMenu, EmptyListPlaceholder } from '@components'
import { Filter } from '@components/filter'
import { localize } from '@core/i18n'
import { PopupId, openPopup } from '@desktop/auxiliary/popup'
import features from '@features/features'
import { SearchInput } from '@ui'
import { writable } from 'svelte/store'
import { CollectiblesTabs } from '../components'
function onReceiveClick(): void {
openPopup({
id: PopupId.ReceiveAddress,
})
}
// MOCKS
const collections: { name: string }[] = []
let collectionSearchTerm = ''
const collectionFilter = writable(undefined)
const ownedCollections = collections
let queriedCollections: typeof collections = []
$: collectionSearchTerm,
$collectionFilter,
(queriedCollections = ownedCollections
.filter((collection) => collection)
.sort((collection1, collection2) =>
collection1.name.toLowerCase().localeCompare(collection2.name.toLowerCase())
))
</script>

<collections-gallery-view class="flex flex-col w-full h-full gap-4">
<header class="flex flex-row items-center justify-between">
<div class="flex flex-row text-left gap-2 items-center flex-1">
<Text type="h6">{localize('views.collectibles.collectionsGallery.title')}</Text>
<Pill color="neutral">
<Text textColor="secondary">{String(queriedCollections.length ?? '')}</Text>
</Pill>
</div>
<CollectiblesTabs />
<div class="flex justify-end items-center gap-5 h-10 shrink-0 flex-1">
{#if collections.length}
<SearchInput bind:value={collectionSearchTerm} />
<Filter filterStore={collectionFilter} />
{/if}
{#if features.collectibles.erc721.enabled}
<CollectiblesListMenu />
{/if}
</div>
</header>
{#if collections.length}
{#if queriedCollections.length}
<!-- <CollectionsGallery collections={queriedCollections} /> -->
{:else}
<div class="w-full h-full flex flex-col items-center justify-center">
<EmptyListPlaceholder
title={localize('views.collectibles.collectionsGallery.noResults')}
icon={IconName.Data}
/>
</div>
{/if}
{:else}
<div class="w-full h-full flex flex-col items-center justify-center grow-1 gap-6">
<EmptyListPlaceholder
title={localize('views.collectibles.collectionsGallery.emptyTitle')}
subtitle={localize('views.collectibles.collectionsGallery.emptyDescription')}
icon={IconName.Data}
/>
<Button text={localize('actions.getStarted')} on:click={onReceiveClick} />
</div>
{/if}
</collections-gallery-view>
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { default as CollectiblesDetailsView } from './CollectiblesDetailsView.svelte'
export { default as CollectiblesGalleryView } from './CollectiblesGalleryView.svelte'
export { default as CollectionsGalleryView } from './CollectionsGalleryView.svelte'
Loading

0 comments on commit 0960f87

Please sign in to comment.