diff options
author | Sebastian <sebasjm@gmail.com> | 2021-07-01 00:35:41 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-07-01 00:35:50 -0300 |
commit | a8e4f2d612fcf29c1b19bed999441211ed51ac08 (patch) | |
tree | 92c3cc110f6a723f659523f1b6d891ee361c0694 /packages/taler-wallet-webextension/src/hooks | |
parent | 23dab91ee9e2ffcac381cc27183716b6881e0a88 (diff) | |
download | wallet-core-a8e4f2d612fcf29c1b19bed999441211ed51ac08.tar.xz |
take backup info from wallet-core
Diffstat (limited to 'packages/taler-wallet-webextension/src/hooks')
-rw-r--r-- | packages/taler-wallet-webextension/src/hooks/useProvidersByCurrency.ts | 106 |
1 files changed, 31 insertions, 75 deletions
diff --git a/packages/taler-wallet-webextension/src/hooks/useProvidersByCurrency.ts b/packages/taler-wallet-webextension/src/hooks/useProvidersByCurrency.ts index 9b600ee2b..dedaf6f86 100644 --- a/packages/taler-wallet-webextension/src/hooks/useProvidersByCurrency.ts +++ b/packages/taler-wallet-webextension/src/hooks/useProvidersByCurrency.ts @@ -1,88 +1,44 @@ import { Amounts } from "@gnu-taler/taler-util"; -// import { ProviderInfo } from "@gnu-taler/taler-wallet-core/src/operations/backup/index.js"; +import { ProviderInfo } from "@gnu-taler/taler-wallet-core/src/operations/backup"; +import { useEffect, useState } from "preact/hooks"; +import * as wxApi from "../wxApi"; export interface ProvidersByCurrency { - [s:string] : any | undefined + [s: string]: ProviderInfo | undefined } - -const list = { - "trustedAuditors": [], - "trustedExchanges": [ - { - "currency": "ARS", - "exchangeBaseUrl": "http://exchange.taler:8081/", - "exchangeMasterPub": "WHA6G542TW8B10N3E857M3P252HV7B896TSP1HP6NREG96ADA4MG" - }, - { - "currency": "KUDOS", - "exchangeBaseUrl": "https://exchange.demo.taler.net/", - "exchangeMasterPub": "FH1Y8ZMHCTPQ0YFSZECDH8C9407JR3YN0MF1706PTG24Q4NEWGV0" - }, - { - "currency": "USD", - "exchangeBaseUrl": "https://exchange.demo.taler.net/", - "exchangeMasterPub": "FH1Y8ZMHCTPQ0YFSZECDH8C9407JR3YN0MF1706PTG24Q4NEWGV0" - }, - { - "currency": "EUR", - "exchangeBaseUrl": "https://exchange.demo.taler.net/", - "exchangeMasterPub": "FH1Y8ZMHCTPQ0YFSZECDH8C9407JR3YN0MF1706PTG24Q4NEWGV0" - } - ] +export interface BackupStatus { + deviceName: string; + providers: ProvidersByCurrency } -const status = { - "deviceId": "thenameofthisdevice", - "walletRootPub": "83DYRKK262TG72H1SD09CTWXQFC151P2DXF9WYH30J8EQ7EAZMCG", - "providers": [ - { - "active": false, - "syncProviderBaseUrl": "http://sync.demo.taler.net/", - "paymentProposalIds": [], - "paymentStatus": { - "type": "unpaid" - }, - "terms": { - "annualFee": "KUDOS:0.1", - "storageLimitInMegabytes": 16, - "supportedProtocolVersion": "0.0" - } - }, { - "active": true, - "syncProviderBaseUrl": "http://sync.taler:9967/", - "lastSuccessfulBackupTimestamp": { - "t_ms": 1625063925078 - }, - "paymentProposalIds": [ - "43Q5WWRJPNS4SE9YKS54H9THDS94089EDGXW9EHBPN6E7M184XEG" - ], - "paymentStatus": { - "type": "paid", - "paidUntil": { - "t_ms": 1656599921000 +export function useBackupStatus(): BackupStatus | undefined { + const [status, setStatus] = useState<BackupStatus | undefined>(undefined) + useEffect(() => { + async function run() { + //create a first list of backup info by currency + const status = await wxApi.getBackupInfo() + const providers = status.providers.reduce((p, c) => { + if (c.terms) { + p[Amounts.parseOrThrow(c.terms.annualFee).currency] = c } - }, - "terms": { - "annualFee": "ARS:1", - "storageLimitInMegabytes": 16, - "supportedProtocolVersion": "0.0" - } - } - - ] -} + return p + }, {} as ProvidersByCurrency) + + //add all the known currency with no backup info + const list = await wxApi.listKnownCurrencies() + const currencies = list.exchanges.map(e => e.name).concat(list.auditors.map(a => a.name)) + currencies.forEach(c => { + if (!providers[c]) { + providers[c] = undefined + } + }) -export function useProvidersByCurrency(): ProvidersByCurrency { - const currencies = list.trustedExchanges.map(e => e.currency) - const providerByCurrency = status.providers.reduce((p, c) => { - if (c.terms) { - p[Amounts.parseOrThrow(c.terms.annualFee).currency] = c + setStatus({ deviceName: status.deviceId, providers }) } - return p - }, {} as Record<string, any | undefined>) + run() + }, []) - - return providerByCurrency + return status } |