importDb feature in wallet core
This commit is contained in:
parent
9f6e398884
commit
5eeb00e158
@ -1294,9 +1294,9 @@ export const WALLET_BACKUP_STATE_KEY = "walletBackupState";
|
|||||||
*/
|
*/
|
||||||
export type ConfigRecord =
|
export type ConfigRecord =
|
||||||
| {
|
| {
|
||||||
key: typeof WALLET_BACKUP_STATE_KEY;
|
key: typeof WALLET_BACKUP_STATE_KEY;
|
||||||
value: WalletBackupConfState;
|
value: WalletBackupConfState;
|
||||||
}
|
}
|
||||||
| { key: "currencyDefaultsApplied"; value: boolean };
|
| { key: "currencyDefaultsApplied"; value: boolean };
|
||||||
|
|
||||||
export interface WalletBackupConfState {
|
export interface WalletBackupConfState {
|
||||||
@ -1480,17 +1480,17 @@ export enum BackupProviderStateTag {
|
|||||||
|
|
||||||
export type BackupProviderState =
|
export type BackupProviderState =
|
||||||
| {
|
| {
|
||||||
tag: BackupProviderStateTag.Provisional;
|
tag: BackupProviderStateTag.Provisional;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
tag: BackupProviderStateTag.Ready;
|
tag: BackupProviderStateTag.Ready;
|
||||||
nextBackupTimestamp: Timestamp;
|
nextBackupTimestamp: Timestamp;
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
tag: BackupProviderStateTag.Retrying;
|
tag: BackupProviderStateTag.Retrying;
|
||||||
retryInfo: RetryInfo;
|
retryInfo: RetryInfo;
|
||||||
lastError?: TalerErrorDetails;
|
lastError?: TalerErrorDetails;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface BackupProviderTerms {
|
export interface BackupProviderTerms {
|
||||||
supportedProtocolVersion: string;
|
supportedProtocolVersion: string;
|
||||||
@ -1873,3 +1873,30 @@ export function exportDb(db: IDBDatabase): Promise<any> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DatabaseDump {
|
||||||
|
name: string,
|
||||||
|
stores: { [s: string]: any },
|
||||||
|
version: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const tx = db.transaction(Array.from(db.objectStoreNames), "readwrite");
|
||||||
|
tx.addEventListener("complete", () => {
|
||||||
|
tx.commit();
|
||||||
|
resolve(db);
|
||||||
|
});
|
||||||
|
for (let i = 0; i < db.objectStoreNames.length; i++) {
|
||||||
|
const name = db.objectStoreNames[i];
|
||||||
|
const storeDump = dump.stores[name];
|
||||||
|
if (!storeDump) continue;
|
||||||
|
Object.keys(storeDump).forEach(async key => {
|
||||||
|
const value = storeDump[key]
|
||||||
|
if (!value) return;
|
||||||
|
tx.objectStore(name).put(value)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user