-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
74 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { apiClient } from "../apiClient"; | ||
import { logAndQuit } from "./errors"; | ||
|
||
export async function getContract(contractId: string) { | ||
const api = await apiClient(); | ||
const { data, response } = await api.GET("/v0/contracts/{id}", { | ||
params: { | ||
path: { id: contractId }, | ||
}, | ||
}); | ||
if (!response.ok) { | ||
return logAndQuit(`Failed to get contract: ${response.statusText}`); | ||
} | ||
return data; | ||
} | ||
|
||
export async function getOrder(orderId: string) { | ||
const api = await apiClient(); | ||
const { data, response, error } = await api.GET("/v0/orders/{id}", { | ||
params: { | ||
path: { id: orderId }, | ||
}, | ||
}); | ||
if (!response.ok) { | ||
// @ts-ignore | ||
if (error?.code === "order.not_found") { | ||
return null; | ||
} | ||
return logAndQuit(`Failed to get order: ${response.statusText}`); | ||
} | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import ora from "ora"; | ||
import chalk from "chalk"; | ||
import { getOrder } from "./fetchers"; | ||
import { logAndQuit } from "./errors"; | ||
|
||
export async function waitForOrderToNotBePending(orderId: string) { | ||
const spinner = ora(`Order ${orderId} - pending (this can take a moment)`).start(); | ||
const maxTries = 25; | ||
for (let i = 0; i < maxTries; i++) { | ||
const order = await getOrder(orderId); | ||
|
||
if (order && order?.status !== "pending") { | ||
spinner.text = `Order ${orderId} - ${order?.status}`; | ||
spinner.succeed(); | ||
console.log(chalk.green("Order placed successfully")); | ||
return order; | ||
} | ||
await new Promise((resolve) => setTimeout(resolve, 500)); | ||
} | ||
|
||
spinner.fail(); | ||
logAndQuit(`Order ${orderId} - possibly failed`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters