aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-07-15 15:03:45 -0300
committerSebastian <sebasjm@gmail.com>2021-07-15 15:05:15 -0300
commit7c2d2a3e15e92b2217e03044f3b9f10b624c2a9b (patch)
tree18d63ee980c28813ba4381f77173a42c774e84c5 /packages
parent18c5371d659222155b27883b2531576af0f86d54 (diff)
simplest implementation to remove one provider, also added a user-defined name for provider
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-core/src/db.ts5
-rw-r--r--packages/taler-wallet-core/src/operations/backup/index.ts32
-rw-r--r--packages/taler-wallet-core/src/wallet.ts7
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
@@ -1587,6 +1587,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
* (such as loading a recovery document).
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<RemoveBackupProviderRequest> =>
+ buildCodecForObject<RemoveBackupProviderRequest>()
+ .property("provider", codecForString())
+ .build("RemoveBackupProviderRequest");
+
+export async function removeBackupProvider(ws: InternalWalletState, req: RemoveBackupProviderRequest): Promise<void> {
+ 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<SyncTermsOfServiceResponse>
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<AddBackupProviderRequest> =>
buildCodecForObject<AddBackupProviderRequest>()
.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<void> {}
-
-export async function restoreFromRecoverySecret(): Promise<void> {}
+export async function restoreFromRecoverySecret(): Promise<void> { }
/**
* Information about one provider.
@@ -676,6 +691,7 @@ export async function restoreFromRecoverySecret(): Promise<void> {}
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;