Skip to content

Commit

Permalink
fix: auto upgrade database version (#1056)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizstacio authored Jan 17, 2024
1 parent 3cc184d commit 5ddd586
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-zoos-rest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'fuels-wallet': patch
---

fix: auto upgrade database
2 changes: 1 addition & 1 deletion packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "fuels-wallet",
"private": true,
"version": "0.14.2",
"database": "13",
"database": "14",
"scripts": {
"build:all": "run-s build:web build:crx build:storybook",
"build:web": "./scripts/build.sh --app=vite",
Expand Down
23 changes: 12 additions & 11 deletions packages/app/src/systems/Core/utils/database.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { createUUID } from '@fuel-wallet/sdk';
import type {
Account,
Vault,
Expand All @@ -10,8 +11,7 @@ import type {
import type { Table } from 'dexie';
import Dexie from 'dexie';
import 'dexie-observable';
import { DECIMAL_UNITS } from 'fuels';
import { DATABASE_VERSION } from '~/config';
import { DATABASE_VERSION, VITE_FUEL_PROVIDER_URL } from '~/config';
import type { Transaction } from '~/systems/Transaction/types';

export class FuelDB extends Dexie {
Expand All @@ -38,15 +38,16 @@ export class FuelDB extends Dexie {
errors: '&id',
})
.upgrade(async (tx) => {
// Update assets to include decimals for
// assets already in the database we set the
// decimals default 9 units.
await tx
.table('assets')
.toCollection()
.modify((asset) => {
asset.decimals = DECIMAL_UNITS;
});
const networks = tx.table('networks');
// Clean networks
await networks.clear();
// Insert beta-5 network
await networks.add({
name: 'Testnet Beta 5',
url: VITE_FUEL_PROVIDER_URL,
isSelected: true,
id: createUUID(),
});
});
}

Expand Down

0 comments on commit 5ddd586

Please sign in to comment.