Skip to content

Commit

Permalink
feat: add contracts table
Browse files Browse the repository at this point in the history
  • Loading branch information
helciofranco committed Jan 1, 2025
1 parent 41eb091 commit 0e6327c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/app/src/systems/Core/utils/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type {
Account,
AssetData,
Connection,
Contract,
DatabaseRestartEvent,
NetworkData,
StoredFuelWalletError,
Expand All @@ -11,12 +12,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 All @@ -31,6 +32,7 @@ export class FuelDB extends Dexie {
transactionsCursors!: Table<TransactionCursor, string>;
assets!: Table<AssetData, string>;
indexedAssets!: Table<FuelCachedAsset, string>;
contracts!: Table<Contract, string>;
abis!: Table<AbiTable, string>;
errors!: Table<StoredFuelWalletError, string>;
integrityCheckInterval?: NodeJS.Timeout;
Expand Down Expand Up @@ -168,6 +170,7 @@ export class FuelDB extends Dexie {
this.transactionsCursors.clear(),
this.assets.clear(),
this.indexedAssets.clear(),
this.contracts.clear(),
this.abis.clear(),
this.errors.clear(),
]);
Expand Down
15 changes: 15 additions & 0 deletions packages/app/src/systems/Core/utils/databaseVersioning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,19 @@ export const applyDbVersioning = (db: Dexie) => {
abis: '&contractId',
errors: '&id',
});

// DB VERSION 29
// add contracts column
db.version(29).stores({
vaults: 'key',
accounts: '&address, &name',
networks: '&id, &url, &name, chainId',
connections: 'origin',
transactionsCursors: '++id, address, size, providerUrl, endCursor',
assets: '&name, &symbol',
contracts: '++id, chainId, contractId, name, image',
indexedAssets: 'key, fetchedAt',
abis: '&contractId',
errors: '&id',
});
};
6 changes: 6 additions & 0 deletions packages/types/src/contract.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface Contract {
chainId: string;
contractId: string;
name: string;
image: string;
}
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export * from './network';
export * from './connection';
export * from './fuel';
export * from './constants';
export * from './contract';
export * from './abi';
export * from './error';
export * from './database';
Expand Down

0 comments on commit 0e6327c

Please sign in to comment.