Skip to content

Commit

Permalink
Merge branch 'master' into Deon-Branch
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielEmmanuel1 authored Jan 8, 2025
2 parents 4c7f835 + 28628cb commit 65d08e5
Show file tree
Hide file tree
Showing 39 changed files with 575 additions and 190 deletions.
5 changes: 5 additions & 0 deletions .changeset/hip-beds-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": patch
---

Allow editing network name when adding.
5 changes: 5 additions & 0 deletions .changeset/plenty-grapes-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels-wallet": minor
---

Improve handling of custom assets.
2 changes: 1 addition & 1 deletion packages/app/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ VITE_CRX_NAME="Fuel Wallet Development"
VITE_CRX_VERSION_API="https://fuellabs.github.io/fuels-wallet/latest.json"
VITE_FUEL_PROVIDER_URL=http://localhost:4000/v1/graphql
VITE_FUEL_FAUCET_URL=http://localhost:4040
VITE_EXPLORER_URL=https://app.fuel.network/
VITE_ECOSYSTEM_PROJECTS_URL=https://fuellabs.github.io/fuel-ecosystem/projects.json
VITE_MNEMONIC_WORDS=12
GENESIS_SECRET=0xa449b1ffee0e2205fa924c6740cc48b3b473aa28587df6dab12abc245d1f5298
VITE_AUTO_LOCK_IN_MINUTES=1
Expand Down
2 changes: 1 addition & 1 deletion packages/app/.env.production
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ VITE_CRX_VERSION_API="https://fuellabs.github.io/fuels-wallet/latest.json"
VITE_CRX_RELEASE=true
VITE_FUEL_PROVIDER_URL=https://testnet.fuel.network/v1/graphql
VITE_FUEL_FAUCET_URL=https://faucet-testnet.fuel.network/
VITE_EXPLORER_URL=https://app.fuel.network/
VITE_ECOSYSTEM_PROJECTS_URL=https://fuellabs.github.io/fuel-ecosystem/projects.json
VITE_MNEMONIC_WORDS=12
VITE_AUTO_LOCK_IN_MINUTES=2880
VITE_SENTRY_DSN=https://f9a5b923067f4f789fb40ed7eccd6486@o4505280621707264.ingest.sentry.io/4505280648577024
24 changes: 24 additions & 0 deletions packages/app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# fuels-wallet

## 0.46.1

### Patch Changes

- [#1753](https://github.com/FuelLabs/fuels-wallet/pull/1753) [`22975202`](https://github.com/FuelLabs/fuels-wallet/commit/22975202ae37ca941f27df825bdea11905cf3ddb) Thanks [@LuizAsFight](https://github.com/LuizAsFight)! - chore: remove comment

- Updated dependencies []:
- @fuel-wallet/connections@0.46.1
- @fuels/playwright-utils@0.46.1

## 0.46.0

### Minor Changes

- [#1749](https://github.com/FuelLabs/fuels-wallet/pull/1749) [`9cb81db2`](https://github.com/FuelLabs/fuels-wallet/commit/9cb81db28009f9879f31eefefe0e08f806bae5f2) Thanks [@helciofranco](https://github.com/helciofranco)! - Add contract logos and names to the transaction screen for better UX.

### Patch Changes

- [#1748](https://github.com/FuelLabs/fuels-wallet/pull/1748) [`cc953d4f`](https://github.com/FuelLabs/fuels-wallet/commit/cc953d4f62402895970140d243a3832a374aaa46) Thanks [@LuizAsFight](https://github.com/LuizAsFight)! - fix: clean opfs when logging out

- Updated dependencies []:
- @fuel-wallet/connections@0.46.0
- @fuels/playwright-utils@0.46.0

## 0.45.0

### Minor Changes
Expand Down
1 change: 1 addition & 0 deletions packages/app/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ declare namespace NodeJS {
VITE_DATABASE_VERSION: string;
readonly VITE_FUEL_PROVIDER_URL: string;
readonly VITE_FUEL_FAUCET_URL: string;
readonly VITE_ECOSYSTEM_PROJECTS_URL: string;
readonly VITE_MNEMONIC_WORDS: string;
readonly VITE_CRX_NAME: string;
readonly VITE_CRX_VERSION_API: string;
Expand Down
4 changes: 1 addition & 3 deletions packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fuels-wallet",
"private": true,
"version": "0.45.0",
"version": "0.46.1",
"type": "module",
"database": "23",
"scripts": {
Expand Down Expand Up @@ -34,7 +34,6 @@
"@sentry/react": "8.33.1",
"@storybook/addon-viewport": "7.4.6",
"@storybook/jest": "0.2.3",
"@tanstack/react-query": "5.28.4",
"@xstate/react": "3.2.2",
"compare-versions": "6.1.0",
"cross-fetch": "4.0.0",
Expand Down Expand Up @@ -84,7 +83,6 @@
"@storybook/react-webpack5": "7.4.6",
"@storybook/testing-library": "0.2.2",
"@storybook/theming": "7.4.6",
"@tanstack/react-query-devtools": "5.28.4",
"@testing-library/react": "14.0.0",
"@types/chrome": "0.0.246",
"@types/lodash.debounce": "4.0.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/app/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ export const {
VITE_CRX_VERSION_API,
VITE_AUTO_LOCK_IN_MINUTES,
VITE_SENTRY_DSN,
VITE_EXPLORER_URL,
VITE_ECOSYSTEM_PROJECTS_URL,
NODE_ENV,
} = import.meta.env;

export const EXPLORER_URL = VITE_EXPLORER_URL;
export const ECOSYSTEM_PROJECTS_URL = VITE_ECOSYSTEM_PROJECTS_URL;
export const WALLET_NAME = VITE_CRX_NAME;
export const APP_VERSION = VITE_APP_VERSION;
export const DATABASE_VERSION = Number(VITE_DATABASE_VERSION);
Expand Down
18 changes: 10 additions & 8 deletions packages/app/src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import type { NetworkData } from '@fuel-wallet/types';
import { CHAIN_IDS } from 'fuels';

export const IGNITION_NETWORK: NetworkData = {
name: 'Ignition',
url: 'https://mainnet.fuel.network/v1/graphql',
chainId: CHAIN_IDS.fuel.mainnet,
explorerUrl: 'https://app.fuel.network',
bridgeUrl: 'https://app.fuel.network/bridge',
isSelected: true,
};

export const DEFAULT_NETWORKS: Array<
NetworkData & { faucetUrl?: string; bridgeUrl?: string; hidden?: boolean }
> = [
{
name: 'Ignition',
url: 'https://mainnet.fuel.network/v1/graphql',
chainId: CHAIN_IDS.fuel.mainnet,
explorerUrl: 'https://app.fuel.network',
bridgeUrl: 'https://app.fuel.network/bridge',
isSelected: true,
},
IGNITION_NETWORK,
{
name: 'Fuel Sepolia Testnet',
url: 'https://testnet.fuel.network/v1/graphql',
Expand Down
7 changes: 5 additions & 2 deletions packages/app/src/systems/Asset/cache/AssetsCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export class AssetsCache {
if (
cachedEntry?.name !== undefined &&
cachedEntry.fetchedAt &&
now - cachedEntry.fetchedAt < FIVE_MINUTES
now - cachedEntry.fetchedAt < FIVE_MINUTES &&
!cachedEntry.isCustom &&
cachedEntry?.name !== ''
) {
return cachedEntry;
}
Expand All @@ -145,7 +147,8 @@ export class AssetsCache {
if (
assetFromDb?.name &&
assetFromDb.fetchedAt &&
now - assetFromDb.fetchedAt < FIVE_MINUTES
now - assetFromDb.fetchedAt < FIVE_MINUTES &&
!assetFromDb.isCustom
) {
this.cache[chainId][assetId] = assetFromDb;
return assetFromDb as FuelCachedAsset;
Expand Down
22 changes: 22 additions & 0 deletions packages/app/src/systems/Contract/hooks/useContractMetadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Contract } from '@fuel-wallet/types';
import { Services, store } from '~/store';
import type { ContractsMachineState } from '../machines/contractsMachine';

const selectors = {
contract(id: string) {
return (state: ContractsMachineState): Contract | undefined => {
return state.context.contracts?.find(
(contract) => contract.contractId === id
);
};
},
};

export const useContractMetadata = (id: string): Contract | undefined => {
const contract = store.useSelector(
Services.contracts,
selectors.contract(id)
);

return contract;
};
81 changes: 81 additions & 0 deletions packages/app/src/systems/Contract/machines/contractsMachine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import type { Contract, EcosystemProject } from '@fuel-wallet/types';
import type { InterpreterFrom, StateFrom } from 'xstate';
import { assign, createMachine } from 'xstate';
import { FetchMachine } from '~/systems/Core';

import { EcosystemService } from '~/systems/Ecosystem/services/ecosystem';
import { ContractService } from '../services/contracts';

export type MachineContext = {
contracts?: Contract[];
};

type MachineServices = {
fetchProjects: {
data: EcosystemProject[];
};
};

export const contractsMachine = createMachine(
{
predictableActionArguments: true,

tsTypes: {} as import('./contractsMachine.typegen').Typegen0,
schema: {
context: {} as MachineContext,
services: {} as MachineServices,
},
id: '(machine)',
initial: 'fetching',
states: {
fetching: {
invoke: {
src: 'fetchProjects',
onDone: [
{
target: 'failure',
cond: FetchMachine.hasError,
},
{
target: 'success',
actions: ['assignContracts'],
},
],
},
},
failure: {
after: {
10000: 'fetching',
},
},
success: {
type: 'final',
},
},
},
{
actions: {
assignContracts: assign({
contracts: (_, ev) => {
return ContractService.formatContractsFromEcosystem(ev.data);
},
}),
},
services: {
fetchProjects: FetchMachine.create<
null,
MachineServices['fetchProjects']['data']
>({
showError: false,
maxAttempts: 1,
async fetch() {
return EcosystemService.fetchProjects();
},
}),
},
}
);

export type ContractsMachine = typeof contractsMachine;
export type ContractsMachineState = StateFrom<ContractsMachine>;
export type ContractsMachineService = InterpreterFrom<ContractsMachine>;
24 changes: 24 additions & 0 deletions packages/app/src/systems/Contract/services/contracts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import type { Contract, EcosystemProject } from '@fuel-wallet/types';
import { CHAIN_IDS } from 'fuels';

// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
export class ContractService {
static formatContractsFromEcosystem(
projects: EcosystemProject[]
): Contract[] {
return projects.flatMap((project) => {
if (!project.contracts?.mainnet) {
return [];
}

return project.contracts.mainnet.map((contract) => {
return {
chainId: CHAIN_IDS.fuel.mainnet,
contractId: contract.id,
name: contract.name,
image: project.image,
};
});
});
}
}
17 changes: 13 additions & 4 deletions packages/app/src/systems/Core/services/core.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import { IS_LOGGED_KEY } from '~/config';
import { clearParallelDb } from '~/systems/Core/utils/databaseNoDexie';
import { VaultService } from '~/systems/Vault';
import { db } from '../utils/database';
import { cleanOPFS } from '../utils/opfs';
import { Storage } from '../utils/storage';
import { chromeStorage } from './chromeStorage';
import { clearParallelDb } from '~/systems/Core/utils/databaseNoDexie';
import { IS_LOGGED_KEY } from '~/config';

// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
export class CoreService {
static async clear() {
await chromeStorage.clear();
await VaultService.clear();
await db.clear();
Storage.clear();
await clearParallelDb();
try {
// this ones can fail depending on environment
Storage.clear();
await chromeStorage.clear();
await cleanOPFS();
} catch (e) {
console.error(e);
}

const reloadAfterCleanCompleted = () => {
const isLogged = Storage.getItem(IS_LOGGED_KEY);
if (!isLogged) {
Expand All @@ -21,6 +29,7 @@ export class CoreService {
}
setTimeout(() => reloadAfterCleanCompleted(), 50);
};

reloadAfterCleanCompleted();
}
}
8 changes: 4 additions & 4 deletions packages/app/src/systems/Core/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import type {
import Dexie, { type DbEvents, type PromiseExtended, type Table } from 'dexie';
import 'dexie-observable';
import type { AssetFuel } from 'fuels';
import { IS_LOGGED_KEY } from '~/config';
import { createParallelDb } from '~/systems/Core/utils/databaseNoDexie';
import { Storage } from '~/systems/Core/utils/storage';
import type { TransactionCursor } from '~/systems/Transaction';
import { chromeStorage } from '../services/chromeStorage';
import { applyDbVersioning } from './databaseVersioning';
import { createParallelDb } from '~/systems/Core/utils/databaseNoDexie';
import { IS_LOGGED_KEY } from '~/config';
import { Storage } from '~/systems/Core/utils/storage';
import { saveToOPFS } from './opfs';

type FailureEvents = Extract<keyof DbEvents, 'close' | 'blocked'>;
Expand Down Expand Up @@ -71,7 +71,7 @@ export class FuelDB extends Dexie {
if (accounts.length && vaults.length && networks.length) {
console.log('saving data to chrome storage', {
accounts,
vaults,
vaults: vaults.length,
networks,
});
for (const account of accounts) {
Expand Down
12 changes: 11 additions & 1 deletion packages/app/src/systems/Core/utils/opfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export async function saveToOPFS(data: any) {

const root = await initOPFS();
if (!root) return;
console.log('saving data to opfs', data);
console.log('saving data to opfs', {
...data,
vaults: data.vaults.length,
});
const fileHandle = await root.getFileHandle('backup.json', { create: true });
const writable = await fileHandle.createWritable();
await writable.write(JSON.stringify(data));
Expand All @@ -35,3 +38,10 @@ export async function readFromOPFS() {
return {};
}
}

// create a function to clean opfs
export async function cleanOPFS() {
const root = await initOPFS();
if (!root) return;
await root.removeEntry('backup.json');
}
16 changes: 16 additions & 0 deletions packages/app/src/systems/Ecosystem/services/ecosystem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { EcosystemProject } from '@fuel-wallet/types';
import { ECOSYSTEM_PROJECTS_URL } from '~/config';

// biome-ignore lint/complexity/noStaticOnlyClass: <explanation>
export class EcosystemService {
static async fetchProjects() {
const res = await fetch(ECOSYSTEM_PROJECTS_URL);

if (res.ok) {
const data: EcosystemProject[] = await res.json();
return data;
}

return [];
}
}
9 changes: 9 additions & 0 deletions packages/app/src/systems/Ecosystem/utils/getProjectImage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { IGNITION_NETWORK } from '~/networks';
import { urlJoin } from '~/systems/Core';

export const getProjectImage = (image: string) => {
return urlJoin(
IGNITION_NETWORK.explorerUrl,
`/api/ecosystem/asset/${image}/image`
);
};
Loading

0 comments on commit 65d08e5

Please sign in to comment.