From 87019285cb3d49ace5f658fffeaf6e7900041c12 Mon Sep 17 00:00:00 2001 From: einaralex Date: Thu, 29 Dec 2022 16:32:52 +0000 Subject: [PATCH] fix: format and lint --- src/client.ts | 58 +++++++++++++++++++++++++++++++-------------- test/client_test.ts | 21 +++++----------- 2 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/client.ts b/src/client.ts index 3a92a45..dc428ec 100644 --- a/src/client.ts +++ b/src/client.ts @@ -47,12 +47,12 @@ export class MoneriumClient { throw new Error("Authentication method could not be detected."); } - this.bearerProfile = await this.#api( + this.bearerProfile = (await this.#api( "post", `auth/token`, new URLSearchParams(params as unknown as Record), true, - ) as BearerProfile; + )) as BearerProfile; this.#authPayload = `Bearer ${this.bearerProfile.access_token}`; } @@ -95,14 +95,19 @@ export class MoneriumClient { getBalances(profileId?: string) { if (profileId) { - return this.#api("get", `profiles/${profileId}/balances`) as Promise; + return this.#api( + "get", + `profiles/${profileId}/balances`, + ) as Promise; } else { return this.#api("get", `balances`) as Promise; } } - getOrders(filter?: OrderFiler) { - const searchParams = new URLSearchParams(filter as unknown as Record); + getOrders(filter?: OrderFilter) { + const searchParams = new URLSearchParams( + filter as unknown as Record, + ); return this.#api("get", `orders?${searchParams}`) as Promise; } @@ -117,22 +122,41 @@ export class MoneriumClient { // -- Write Methods + linkAddress(profileId: string, body: LinkAddress) { + return this.#api( + "post", + `profiles/${profileId}/addresses`, + JSON.stringify(body), + ); + } + placeOrder(order: NewOrder, profileId?: string) { if (profileId) { - return this.#api("post", `profiles/${profileId}/orders`, JSON.stringify(order)) as Promise< - Order - >; + return this.#api( + "post", + `profiles/${profileId}/orders`, + JSON.stringify(order), + ) as Promise; } else { - return this.#api("post", `orders`, JSON.stringify(order)) as Promise; + return this.#api( + "post", + `orders`, + JSON.stringify(order), + ) as Promise; } } uploadSupportingDocument(document: File) { - const searchParams = new URLSearchParams(document as unknown as Record); + const searchParams = new URLSearchParams( + document as unknown as Record, + ); - return this.#api("post", "files/supporting-document", searchParams, true) as Promise< - SupportingDoc - >; + return this.#api( + "post", + "files/supporting-document", + searchParams, + true, + ) as Promise; } // -- Helper Methods @@ -141,20 +165,18 @@ export class MoneriumClient { method: string, resource: string, body?: BodyInit, - isFormEncoded?: boolean + isFormEncoded?: boolean, ) { const res = await fetch(`${this.#env.api}/${resource}`, { method, headers: { - "Content-Type": `application/${ - isFormEncoded ? "x-www-form-urlencoded" : "json" - }`, + "Content-Type": `application/${isFormEncoded ? "x-www-form-urlencoded" : "json"}`, Authorization: this.#authPayload || "", }, body, }); - let response = await res.json(); + const response = await res.json(); if (res.ok) { return response; diff --git a/test/client_test.ts b/test/client_test.ts index 839d94e..8b3ea16 100644 --- a/test/client_test.ts +++ b/test/client_test.ts @@ -1,28 +1,19 @@ import { assertArrayIncludes, + assertEquals, assertInstanceOf, assertObjectMatch, - assertEquals, } from "https://deno.land/std@0.168.0/testing/asserts.ts"; import { MoneriumClient } from "../mod.ts"; -import { - Chain, - Currency, - Network, - OrderKind, - PaymentStandard, - Order, -} from "../src/types.ts"; +import { Chain, Currency, Network, Order, OrderKind, PaymentStandard } from "../src/types.ts"; const clientId = "654c9c30-44d3-11ed-adac-b2efc0e6677d"; -const clientSecret = - "ac474b7cdc111973aa080b0428ba3a824e82119bee8f65875b4aba0d42416dff"; +const clientSecret = "ac474b7cdc111973aa080b0428ba3a824e82119bee8f65875b4aba0d42416dff"; // punkWallet: https://punkwallet.io/pk#0x3e4936f901535680c505b073a5f70094da38e2085ecf137b153d1866a7aa826b +// const privateKey = "0x3e4936f901535680c505b073a5f70094da38e2085ecf137b153d1866a7aa826b"; const publicKey = "0x2d312198e570912844b5a230AE6f7A2E3321371C"; -const privateKey = - "0x3e4936f901535680c505b073a5f70094da38e2085ecf137b153d1866a7aa826b"; const message = "I hereby declare that I am the address owner."; @@ -129,7 +120,7 @@ Deno.test("get orders", async () => { const orders = await client.getOrders(); const order = orders.find( - (o: Order) => o.memo === "Powered by Monerium SDK" + (o: Order) => o.memo === "Powered by Monerium SDK", ) as Order; assertArrayIncludes(orders, []); @@ -212,7 +203,7 @@ Deno.test("place order", async () => { (a) => a.address === publicKey && a.currency === Currency.eur && - a.network === Network.goerli + a.network === Network.goerli, ); const date = "Thu, 29 Dec 2022 14:58 +00:00";