mirror of
https://github.com/pezkuwichain/pezkuwi-apps.git
synced 2026-10-20 18:56:30 +00:00
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
// Copyright 2017-2026 @pezkuwi/apps authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
// @ts-ignore Warned on by nodenext resolution (while package does build in bundler mode)
|
|
import type { KeyringJson, KeyringStore } from '@pezkuwi/ui-keyring/types';
|
|
import type { AccountStoreApi } from '../api/account-store-api.js';
|
|
|
|
export class RemoteElectronStore implements KeyringStore {
|
|
readonly #accountStore: AccountStoreApi;
|
|
|
|
constructor (accountStore: AccountStoreApi) {
|
|
this.#accountStore = accountStore;
|
|
}
|
|
|
|
all (cb: (key: string, value: KeyringJson) => void): void {
|
|
this.#accountStore.all()
|
|
.then((result: { key: string, value: KeyringJson }[]) => result?.forEach(({ key, value }) => cb(key, value)))
|
|
.catch((e: Error) => {
|
|
throw new Error(`error getting all accounts: ${e.message}`);
|
|
});
|
|
}
|
|
|
|
get (key: string, cb: (value: KeyringJson) => void): void {
|
|
this.#accountStore.get(key)
|
|
.then(cb).catch((e: Error) => {
|
|
throw new Error(`error storing account: ${e.message}`);
|
|
});
|
|
}
|
|
|
|
remove (key: string, cb: (() => void) | undefined): void {
|
|
this.#accountStore.remove(key).then(cb).catch((e: Error) => {
|
|
throw new Error(`error removing account: ${e.message}`);
|
|
});
|
|
}
|
|
|
|
set (key: string, value: KeyringJson, cb: (() => void) | undefined): void {
|
|
this.#accountStore.set(key, value).then(cb).catch((e: Error) => {
|
|
throw new Error(`error saving account: ${e.message}`);
|
|
});
|
|
}
|
|
}
|