Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
fix: format and lint
Browse files Browse the repository at this point in the history
  • Loading branch information
einaralex committed Dec 29, 2022
1 parent f521fb3 commit 8701928
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
58 changes: 40 additions & 18 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>),
true,
) as BearerProfile;
)) as BearerProfile;

this.#authPayload = `Bearer ${this.bearerProfile.access_token}`;
}
Expand Down Expand Up @@ -95,14 +95,19 @@ export class MoneriumClient {

getBalances(profileId?: string) {
if (profileId) {
return this.#api("get", `profiles/${profileId}/balances`) as Promise<Balances>;
return this.#api(
"get",
`profiles/${profileId}/balances`,
) as Promise<Balances>;
} else {
return this.#api("get", `balances`) as Promise<Balances[]>;
}
}

getOrders(filter?: OrderFiler) {
const searchParams = new URLSearchParams(filter as unknown as Record<string, string>);
getOrders(filter?: OrderFilter) {
const searchParams = new URLSearchParams(
filter as unknown as Record<string, string>,
);

return this.#api("get", `orders?${searchParams}`) as Promise<Order[]>;
}
Expand All @@ -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<Order>;
} else {
return this.#api("post", `orders`, JSON.stringify(order)) as Promise<Order>;
return this.#api(
"post",
`orders`,
JSON.stringify(order),
) as Promise<Order>;
}
}

uploadSupportingDocument(document: File) {
const searchParams = new URLSearchParams(document as unknown as Record<string, string>);
const searchParams = new URLSearchParams(
document as unknown as Record<string, string>,
);

return this.#api("post", "files/supporting-document", searchParams, true) as Promise<
SupportingDoc
>;
return this.#api(
"post",
"files/supporting-document",
searchParams,
true,
) as Promise<SupportingDoc>;
}

// -- Helper Methods
Expand All @@ -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;
Expand Down
21 changes: 6 additions & 15 deletions test/client_test.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
import {
assertArrayIncludes,
assertEquals,
assertInstanceOf,
assertObjectMatch,
assertEquals,
} from "https://deno.land/[email protected]/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.";

Expand Down Expand Up @@ -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, []);
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 8701928

Please sign in to comment.