summaryrefslogtreecommitdiff
path: root/packages/taler-wallet-webextension/src/hooks
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks')
-rw-r--r--packages/taler-wallet-webextension/src/hooks/useBackupStatus.ts (renamed from packages/taler-wallet-webextension/src/hooks/useProvidersByCurrency.ts)13
-rw-r--r--packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts34
2 files changed, 43 insertions, 4 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useProvidersByCurrency.ts b/packages/taler-wallet-webextension/src/hooks/useBackupStatus.ts
index 09f61e468..2d51cb303 100644
--- a/packages/taler-wallet-webextension/src/hooks/useProvidersByCurrency.ts
+++ b/packages/taler-wallet-webextension/src/hooks/useBackupStatus.ts
@@ -1,12 +1,12 @@
-import { Amounts } from "@gnu-taler/taler-util";
import { ProviderInfo, ProviderPaymentPaid, ProviderPaymentStatus, ProviderPaymentType } from "@gnu-taler/taler-wallet-core";
import { useEffect, useState } from "preact/hooks";
-
import * as wxApi from "../wxApi";
+
export interface BackupStatus {
deviceName: string;
- providers: ProviderInfo[]
+ providers: ProviderInfo[];
+ sync: () => Promise<void>;
}
function getStatusTypeOrder(t: ProviderPaymentStatus) {
@@ -40,7 +40,11 @@ export function useBackupStatus(): BackupStatus | undefined {
return getStatusTypeOrder(a.paymentStatus) - getStatusTypeOrder(b.paymentStatus)
})
- setStatus({ deviceName: status.deviceId, providers })
+ async function sync() {
+ await wxApi.syncAllProviders()
+ }
+
+ setStatus({ deviceName: status.deviceId, providers, sync })
}
run()
}, [])
@@ -48,3 +52,4 @@ export function useBackupStatus(): BackupStatus | undefined {
return status
}
+
diff --git a/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts b/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts
new file mode 100644
index 000000000..42eab5d80
--- /dev/null
+++ b/packages/taler-wallet-webextension/src/hooks/useProviderStatus.ts
@@ -0,0 +1,34 @@
+import { ProviderInfo } from "@gnu-taler/taler-wallet-core";
+import { useEffect, useState } from "preact/hooks";
+import * as wxApi from "../wxApi";
+
+export interface ProviderStatus {
+ info?: ProviderInfo;
+ sync: () => Promise<void>;
+}
+
+export function useProviderStatus(url: string): ProviderStatus | undefined {
+ const [status, setStatus] = useState<ProviderStatus | undefined>(undefined);
+
+ useEffect(() => {
+ async function run() {
+ //create a first list of backup info by currency
+ const status = await wxApi.getBackupInfo();
+
+ const providers = status.providers.filter(p => p.syncProviderBaseUrl === url);
+ const info = providers.length ? providers[0] : undefined;
+
+ async function sync() {
+ console.log("que tiene info", info)
+ if (info) {
+ await wxApi.syncOneProvider(info.syncProviderBaseUrl);
+ }
+ }
+
+ setStatus({ info, sync });
+ }
+ run();
+ }, []);
+
+ return status;
+}