diff --git a/app/database/DappDatabase.ts b/app/database/DappDatabase.ts index 7f0bbabe..32f2b1a0 100644 --- a/app/database/DappDatabase.ts +++ b/app/database/DappDatabase.ts @@ -7,11 +7,6 @@ import { import { CoinType } from "core/types"; export class DappDatabase extends Dexie { - /** - * @deprecated - */ - aleo_history: Dexie.Table; - dapp_history: Dexie.Table; request: Dexie.Table; @@ -31,22 +26,41 @@ export class DappDatabase extends Dexie { .stores({ dapp_history: "++id, [address+coinType+network], site.origin", }) - .upgrade(async (tx) => - // TODO check this - this.aleo_history.each( - async (aleoHistory) => - this.dapp_history?.add({ - ...aleoHistory, - coinType: CoinType.ALEO, - }), - ), - ); + .upgrade(async (tx) => { + const aleoHistories = (await tx + .table("aleo_history") + .toArray()) as AleoConnectHistory[]; + if (!aleoHistories.length) { + return; + } + + await tx.table("dapp_history").bulkAdd( + aleoHistories.map((aleoHistory) => ({ + ...aleoHistory, + coinType: CoinType.ALEO, + })), + ); + }); this.version(4).stores({ aleo_history: null, aleo_connect_history: null, }); + this.version(5).upgrade(async (tx) => { + await tx + .table("dapp_history") + .filter((history: Partial) => !history.coinType) + .modify((history: Partial) => { + history.coinType = history.address?.startsWith("aleo1") + ? CoinType.ALEO + : CoinType.ETH; + if (history.coinType === CoinType.ETH && !history.network) { + history.network = ""; + } + }); + }); + this.dapp_history = this.table("dapp_history"); this.request = this.table("request"); }