From 7c2d2a3e15e92b2217e03044f3b9f10b624c2a9b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 15 Jul 2021 15:03:45 -0300 Subject: [PATCH] simplest implementation to remove one provider, also added a user-defined name for provider --- packages/taler-wallet-core/src/db.ts | 5 +++ .../src/operations/backup/index.ts | 32 +++++++++++++++---- packages/taler-wallet-core/src/wallet.ts | 7 ++++ 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 2a2aba461..0bb8db17a 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1586,6 +1586,11 @@ export interface BackupProviderRecord { */ baseUrl: string; + /** + * Name of the provider + */ + name: string; + /** * Terms of service of the provider. * Might be unavailable in the DB in certain situations diff --git a/packages/taler-wallet-core/src/operations/backup/index.ts b/packages/taler-wallet-core/src/operations/backup/index.ts index 9593325a3..3799741ee 100644 --- a/packages/taler-wallet-core/src/operations/backup/index.ts +++ b/packages/taler-wallet-core/src/operations/backup/index.ts @@ -304,8 +304,8 @@ async function runBackupCycleForProvider( "if-none-match": encodeCrock(currentBackupHash), ...(provider.lastBackupHash ? { - "if-match": provider.lastBackupHash, - } + "if-match": provider.lastBackupHash, + } : {}), }, }); @@ -522,6 +522,21 @@ export async function processBackupForProvider( await guardOperationException(run, onOpErr); } +export interface RemoveBackupProviderRequest { + provider: string; +} + +export const codecForRemoveBackupProvider = (): Codec => + buildCodecForObject() + .property("provider", codecForString()) + .build("RemoveBackupProviderRequest"); + +export async function removeBackupProvider(ws: InternalWalletState, req: RemoveBackupProviderRequest): Promise { + await ws.db.mktx(({ backupProviders }) => ({ backupProviders })) + .runReadWrite(async (tx) => { + await tx.backupProviders.delete(req.provider) + }) +} export interface RunBackupCycleRequest { /** @@ -590,6 +605,8 @@ const codecForSyncTermsOfServiceResponse = (): Codec export interface AddBackupProviderRequest { backupProviderBaseUrl: string; + + name: string; /** * Activate the provider. Should only be done after * the user has reviewed the provider. @@ -600,6 +617,7 @@ export interface AddBackupProviderRequest { export const codecForAddBackupProviderRequest = (): Codec => buildCodecForObject() .property("backupProviderBaseUrl", codecForString()) + .property("name", codecForString()) .property("activate", codecOptional(codecForBoolean())) .build("AddBackupProviderRequest"); @@ -649,6 +667,7 @@ export async function addBackupProvider( } await tx.backupProviders.put({ state, + name: req.name, terms: { annualFee: terms.annual_fee, storageLimitInMegabytes: terms.storage_limit_in_megabytes, @@ -661,11 +680,7 @@ export async function addBackupProvider( }); } -export async function removeBackupProvider( - syncProviderBaseUrl: string, -): Promise {} - -export async function restoreFromRecoverySecret(): Promise {} +export async function restoreFromRecoverySecret(): Promise { } /** * Information about one provider. @@ -676,6 +691,7 @@ export async function restoreFromRecoverySecret(): Promise {} export interface ProviderInfo { active: boolean; syncProviderBaseUrl: string; + name: string; terms?: BackupProviderTerms; /** * Last communication issue with the provider. @@ -830,6 +846,7 @@ export async function getBackupInfo( : undefined, paymentStatus: await getProviderPaymentInfo(ws, x), terms: x.terms, + name: x.name, }); } return { @@ -890,6 +907,7 @@ async function backupRecoveryTheirs( if (!existingProv) { await tx.backupProviders.put({ baseUrl: prov.url, + name: 'not-defined', paymentProposalIds: [], state: { tag: BackupProviderStateTag.Ready, diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index d46914b37..e6d541e9d 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -41,11 +41,13 @@ import { import { addBackupProvider, codecForAddBackupProviderRequest, + codecForRemoveBackupProvider, codecForRunBackupCycle, getBackupInfo, getBackupRecovery, loadBackupRecovery, processBackupForProvider, + removeBackupProvider, runBackupCycle, } from "./operations/backup/index.js"; import { exportBackup } from "./operations/backup/export.js"; @@ -814,6 +816,11 @@ async function dispatchRequestInternal( await runBackupCycle(ws, req); return {}; } + case "removeBackupProvider": { + const req = codecForRemoveBackupProvider().decode(payload); + await removeBackupProvider(ws, req); + return {}; + } case "exportBackupRecovery": { const resp = await getBackupRecovery(ws); return resp;