take backup info from wallet-core
This commit is contained in:
parent
23dab91ee9
commit
a8e4f2d612
@ -1,88 +1,44 @@
|
|||||||
import { Amounts } from "@gnu-taler/taler-util";
|
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 {
|
export interface ProvidersByCurrency {
|
||||||
[s:string] : any | undefined
|
[s: string]: ProviderInfo | undefined
|
||||||
|
}
|
||||||
|
export interface BackupStatus {
|
||||||
|
deviceName: string;
|
||||||
|
providers: ProvidersByCurrency
|
||||||
}
|
}
|
||||||
|
|
||||||
const list = {
|
export function useBackupStatus(): BackupStatus | undefined {
|
||||||
"trustedAuditors": [],
|
const [status, setStatus] = useState<BackupStatus | undefined>(undefined)
|
||||||
"trustedExchanges": [
|
useEffect(() => {
|
||||||
{
|
async function run() {
|
||||||
"currency": "ARS",
|
//create a first list of backup info by currency
|
||||||
"exchangeBaseUrl": "http://exchange.taler:8081/",
|
const status = await wxApi.getBackupInfo()
|
||||||
"exchangeMasterPub": "WHA6G542TW8B10N3E857M3P252HV7B896TSP1HP6NREG96ADA4MG"
|
const providers = status.providers.reduce((p, c) => {
|
||||||
},
|
if (c.terms) {
|
||||||
{
|
p[Amounts.parseOrThrow(c.terms.annualFee).currency] = c
|
||||||
"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"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
},
|
return p
|
||||||
"terms": {
|
}, {} as ProvidersByCurrency)
|
||||||
"annualFee": "ARS:1",
|
|
||||||
"storageLimitInMegabytes": 16,
|
|
||||||
"supportedProtocolVersion": "0.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
]
|
//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))
|
||||||
export function useProvidersByCurrency(): ProvidersByCurrency {
|
currencies.forEach(c => {
|
||||||
const currencies = list.trustedExchanges.map(e => e.currency)
|
if (!providers[c]) {
|
||||||
const providerByCurrency = status.providers.reduce((p, c) => {
|
providers[c] = undefined
|
||||||
if (c.terms) {
|
}
|
||||||
p[Amounts.parseOrThrow(c.terms.annualFee).currency] = c
|
})
|
||||||
}
|
|
||||||
return p
|
setStatus({ deviceName: status.deviceId, providers })
|
||||||
}, {} as Record<string, any | undefined>)
|
}
|
||||||
|
run()
|
||||||
|
}, [])
|
||||||
return providerByCurrency
|
|
||||||
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
* @author Sebastian Javier Marchano (sebasjm)
|
* @author Sebastian Javier Marchano (sebasjm)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { ProviderPaymentType } from '@gnu-taler/taler-wallet-core/src/operations/backup';
|
||||||
import { FunctionalComponent } from 'preact';
|
import { FunctionalComponent } from 'preact';
|
||||||
import { BackupView as TestedComponent } from './BackupPage';
|
import { BackupView as TestedComponent } from './BackupPage';
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ export const Example = createExample(TestedComponent, {
|
|||||||
"43Q5WWRJPNS4SE9YKS54H9THDS94089EDGXW9EHBPN6E7M184XEG"
|
"43Q5WWRJPNS4SE9YKS54H9THDS94089EDGXW9EHBPN6E7M184XEG"
|
||||||
],
|
],
|
||||||
"paymentStatus": {
|
"paymentStatus": {
|
||||||
"type": 'paid',
|
"type": ProviderPaymentType.Paid,
|
||||||
"paidUntil": {
|
"paidUntil": {
|
||||||
"t_ms": 1656599921000
|
"t_ms": 1656599921000
|
||||||
}
|
}
|
||||||
@ -68,7 +69,7 @@ export const Example = createExample(TestedComponent, {
|
|||||||
"syncProviderBaseUrl": "http://sync.demo.taler.net/",
|
"syncProviderBaseUrl": "http://sync.demo.taler.net/",
|
||||||
"paymentProposalIds": [],
|
"paymentProposalIds": [],
|
||||||
"paymentStatus": {
|
"paymentStatus": {
|
||||||
"type": 'unpaid',
|
"type": ProviderPaymentType.Unpaid,
|
||||||
},
|
},
|
||||||
"terms": {
|
"terms": {
|
||||||
"annualFee": "KUDOS:0.1",
|
"annualFee": "KUDOS:0.1",
|
||||||
|
@ -19,11 +19,14 @@ import { Timestamp } from "@gnu-taler/taler-util";
|
|||||||
// import { ProviderPaymentStatus } from "@gnu-taler/taler-wallet-core/src/operations/backup";
|
// import { ProviderPaymentStatus } from "@gnu-taler/taler-wallet-core/src/operations/backup";
|
||||||
import { formatDuration, intervalToDuration } from "date-fns";
|
import { formatDuration, intervalToDuration } from "date-fns";
|
||||||
import { JSX, VNode } from "preact";
|
import { JSX, VNode } from "preact";
|
||||||
import { ProvidersByCurrency, useProvidersByCurrency } from "../hooks/useProvidersByCurrency";
|
import { ProvidersByCurrency, useBackupStatus } from "../hooks/useProvidersByCurrency";
|
||||||
|
|
||||||
export function BackupPage(): VNode {
|
export function BackupPage(): VNode {
|
||||||
const providers = useProvidersByCurrency()
|
const status = useBackupStatus()
|
||||||
return <BackupView deviceName={"thisdevicename"} providers={providers}/>;
|
if (!status) {
|
||||||
|
return <div>Loading...</div>
|
||||||
|
}
|
||||||
|
return <BackupView deviceName={status.deviceName} providers={status.providers}/>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ViewProps {
|
export interface ViewProps {
|
||||||
|
@ -38,7 +38,8 @@ import {
|
|||||||
DeleteTransactionRequest,
|
DeleteTransactionRequest,
|
||||||
RetryTransactionRequest,
|
RetryTransactionRequest,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import { OperationFailedError } from "@gnu-taler/taler-wallet-core";
|
import { BackupProviderState, OperationFailedError } from "@gnu-taler/taler-wallet-core";
|
||||||
|
import { BackupInfo } from "@gnu-taler/taler-wallet-core/src/operations/backup";
|
||||||
|
|
||||||
export interface ExtendedPermissionsResponse {
|
export interface ExtendedPermissionsResponse {
|
||||||
newValue: boolean;
|
newValue: boolean;
|
||||||
@ -132,18 +133,48 @@ export function getTransactions(): Promise<TransactionsResponse> {
|
|||||||
return callBackend("getTransactions", {});
|
return callBackend("getTransactions", {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface CurrencyInfo {
|
||||||
|
name: string;
|
||||||
|
baseUrl: string;
|
||||||
|
pub: string;
|
||||||
|
}
|
||||||
|
interface ListOfKnownCurrencies {
|
||||||
|
auditors: CurrencyInfo[],
|
||||||
|
exchanges: CurrencyInfo[],
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get currency from known auditors and exchanges
|
* Get a list of currencies from known auditors and exchanges
|
||||||
*/
|
*/
|
||||||
export function listCurrencies(): Promise<TransactionsResponse> {
|
export function listKnownCurrencies(): Promise<ListOfKnownCurrencies> {
|
||||||
return callBackend("listCurrencies", {});
|
return callBackend("listCurrencies", {}).then(result => {
|
||||||
|
console.log("result list", result)
|
||||||
|
const auditors = result.trustedAuditors.map((a: Record<string, string>) => ({
|
||||||
|
name: a.currency,
|
||||||
|
baseUrl: a.auditorBaseUrl,
|
||||||
|
pub: a.auditorPub,
|
||||||
|
}))
|
||||||
|
const exchanges = result.trustedExchanges.map((a: Record<string, string>) => ({
|
||||||
|
name: a.currency,
|
||||||
|
baseUrl: a.exchangeBaseUrl,
|
||||||
|
pub: a.exchangeMasterPub,
|
||||||
|
}))
|
||||||
|
return { auditors, exchanges }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get information about the current state of wallet backups.
|
||||||
|
*/
|
||||||
|
export function getBackupInfo(): Promise<BackupInfo> {
|
||||||
|
return callBackend("getBackupInfo", {})
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Retry a transaction
|
* Retry a transaction
|
||||||
* @param transactionId
|
* @param transactionId
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function retryTransaction(transactionId: string): Promise<void> {
|
export function retryTransaction(transactionId: string): Promise<void> {
|
||||||
return callBackend("retryTransaction", {
|
return callBackend("retryTransaction", {
|
||||||
transactionId
|
transactionId
|
||||||
} as RetryTransactionRequest);
|
} as RetryTransactionRequest);
|
||||||
|
Loading…
Reference in New Issue
Block a user