-
Notifications
You must be signed in to change notification settings - Fork 12
/
order.ts
65 lines (62 loc) · 1.5 KB
/
order.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { Command } from "@oclif/command";
import chalk from "chalk";
import { cancelled, get } from "../lib/prompt";
import * as requests from "../lib/requests";
import * as utils from "../lib/utils";
import { getWallet } from "../lib/wallet";
export default class Order extends Command {
public static description = "get an order from a server";
public async run() {
try {
const wallet = await getWallet(this);
const chainId = (await wallet.provider.getNetwork()).chainId;
const metadata = await utils.getMetadata(this, chainId);
const gasPrice = await utils.getGasPrice(this);
utils.displayDescription(this, Order.description, chainId);
const { locator }: any = await get({
locator: {
type: "Locator",
},
});
const request = await requests.getRequest(wallet, metadata, "Order");
this.log();
requests.peerCall(
locator,
request.method,
request.params,
async (err, order) => {
if (err) {
if (err === "timeout") {
this.log(chalk.yellow("The request timed out.\n"));
} else {
cancelled(err);
}
process.exit(0);
} else {
try {
await requests.validateResponse(
order,
request.method,
request.params,
wallet,
);
utils.handleResponse(
request,
wallet,
metadata,
chainId,
gasPrice,
this,
order,
);
} catch (e) {
cancelled(e);
}
}
},
);
} catch (e) {
cancelled(e);
}
}
}