diff options
author | Sebastian <sebasjm@gmail.com> | 2022-06-06 00:09:25 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2022-06-06 00:09:25 -0300 |
commit | fb6aff76d2152d95caa2ba6cb0d91cb01e0687fe (patch) | |
tree | 2dc9b0a4935f60ba7229fd81332ec4a41ad4698c /packages/taler-wallet-webextension/src/utils/index.ts | |
parent | 912813fd09ee2f757e4d6d509a911159b46153a7 (diff) | |
download | wallet-core-fb6aff76d2152d95caa2ba6cb0d91cb01e0687fe.tar.xz |
prettier
Diffstat (limited to 'packages/taler-wallet-webextension/src/utils/index.ts')
-rw-r--r-- | packages/taler-wallet-webextension/src/utils/index.ts | 75 |
1 files changed, 43 insertions, 32 deletions
diff --git a/packages/taler-wallet-webextension/src/utils/index.ts b/packages/taler-wallet-webextension/src/utils/index.ts index 9181ee5b6..ae2705eb2 100644 --- a/packages/taler-wallet-webextension/src/utils/index.ts +++ b/packages/taler-wallet-webextension/src/utils/index.ts @@ -14,8 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ -import { AmountJson, Amounts, GetExchangeTosResult } from "@gnu-taler/taler-util"; - +import { + AmountJson, + Amounts, + GetExchangeTosResult, +} from "@gnu-taler/taler-util"; function getJsonIfOk(r: Response): Promise<any> { if (r.ok) { @@ -27,15 +30,13 @@ function getJsonIfOk(r: Response): Promise<any> { } throw new Error( - `Try another server: (${r.status}) ${r.statusText || "internal server error" + `Try another server: (${r.status}) ${ + r.statusText || "internal server error" }`, ); - } -export async function queryToSlashConfig<T>( - url: string, -): Promise<T> { +export async function queryToSlashConfig<T>(url: string): Promise<T> { return fetch(new URL("config", url).href) .catch(() => { throw new Error(`Network error`); @@ -46,25 +47,27 @@ export async function queryToSlashConfig<T>( function timeout<T>(ms: number, promise: Promise<T>): Promise<T> { return new Promise((resolve, reject) => { const timer = setTimeout(() => { - reject(new Error(`Timeout: the query took longer than ${Math.floor(ms / 1000)} secs`)) - }, ms) + reject( + new Error( + `Timeout: the query took longer than ${Math.floor(ms / 1000)} secs`, + ), + ); + }, ms); promise - .then(value => { - clearTimeout(timer) - resolve(value) + .then((value) => { + clearTimeout(timer); + resolve(value); }) - .catch(reason => { - clearTimeout(timer) - reject(reason) - }) - }) + .catch((reason) => { + clearTimeout(timer); + reject(reason); + }); + }); } -export async function queryToSlashKeys<T>( - url: string, -): Promise<T> { - const endpoint = new URL("keys", url) +export async function queryToSlashKeys<T>(url: string): Promise<T> { + const endpoint = new URL("keys", url); endpoint.searchParams.set("cacheBreaker", new Date().getTime() + ""); const query = fetch(endpoint.href) @@ -73,29 +76,37 @@ export async function queryToSlashKeys<T>( }) .then(getJsonIfOk); - return timeout(3000, query) + return timeout(3000, query); } -export function buildTermsOfServiceState(tos: GetExchangeTosResult): TermsState { - +export function buildTermsOfServiceState( + tos: GetExchangeTosResult, +): TermsState { const content: TermsDocument | undefined = parseTermsOfServiceContent( tos.contentType, tos.content, ); - const status: TermsStatus = buildTermsOfServiceStatus(tos.content, tos.acceptedEtag, tos.currentEtag); - - return { content, status, version: tos.currentEtag } + const status: TermsStatus = buildTermsOfServiceStatus( + tos.content, + tos.acceptedEtag, + tos.currentEtag, + ); + return { content, status, version: tos.currentEtag }; } -export function buildTermsOfServiceStatus(content: string | undefined, acceptedVersion: string | undefined, currentVersion: string | undefined): TermsStatus { +export function buildTermsOfServiceStatus( + content: string | undefined, + acceptedVersion: string | undefined, + currentVersion: string | undefined, +): TermsStatus { return !content ? "notfound" : !acceptedVersion - ? "new" - : acceptedVersion !== currentVersion - ? "changed" - : "accepted"; + ? "new" + : acceptedVersion !== currentVersion + ? "changed" + : "accepted"; } function parseTermsOfServiceContent( |