Skip to content

Commit c2f1358

Browse files
committed
fix buy error
1 parent 7bba62c commit c2f1358

1 file changed

Lines changed: 32 additions & 46 deletions

File tree

src/lib/buy.ts

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -218,62 +218,48 @@ async function buyOrderAction(options: SfBuyOptions) {
218218
return;
219219
}
220220

221-
switch (order.status) {
222-
case "pending": {
223-
const orderId = res.id;
224-
const printOrderNumber = (status: string) =>
225-
console.log(`\n${c.dim(`${orderId}\n\n`)}`);
221+
if (order.status === "filled") {
222+
const now = new Date();
223+
const startAt = new Date(order.start_at);
224+
const timeDiff = startAt.getTime() - now.getTime();
225+
const oneMinuteInMs = 60 * 1000;
226226

227-
const order = await tryToGetOrder(orderId);
227+
if (now >= startAt || timeDiff <= oneMinuteInMs) {
228+
console.log(`Your nodes are currently spinning up. Once they're online, you can view them using:
228229
229-
if (!order) {
230-
console.log(`\n${c.dim(`Order ${orderId} is pending`)}`);
231-
return;
232-
}
233-
printOrderNumber(order.status);
230+
sf instances ls
234231
235-
if (order.status === "filled") {
236-
const now = new Date();
237-
const startAt = new Date(order.start_at);
238-
const timeDiff = startAt.getTime() - now.getTime();
239-
const oneMinuteInMs = 60 * 1000;
232+
`);
233+
} else {
234+
const contractStartTime = dayjs(startAt);
235+
const timeFromNow = contractStartTime.fromNow();
236+
console.log(`Your contract begins ${c.green(timeFromNow)}. You can view more details using:
240237
241-
if (now >= startAt || timeDiff <= oneMinuteInMs) {
242-
console.log(`Your nodes are currently spinning up. Once they're online, you can view them using:
238+
sf contracts ls
243239
244-
sf instances ls
245-
246-
`);
247-
} else {
248-
const contractStartTime = dayjs(startAt);
249-
const timeFromNow = contractStartTime.fromNow();
250-
console.log(`Your contract begins ${c.green(timeFromNow)}. You can view more details using:
251-
252-
sf contracts ls
240+
`);
241+
}
242+
return
243+
}
253244

254-
`);
255-
}
245+
if (order.status === "open") {
246+
console.log(`Your order wasn't accepted yet. You can check it's status with:
247+
248+
sf orders ls
249+
250+
If you want to cancel the order, you can do so with:
251+
252+
sf orders cancel ${order.id}
253+
254+
`);
255+
return
256+
}
256257

257-
return;
258-
} else {
259-
console.log(`Your order wasn't accepted yet. You can check it's status with:
258+
console.error(`Order likely did not execute. Check the status with:
260259
261260
sf orders ls
262261
263-
If you want to cancel the order, you can do so with:
264-
265-
sf orders cancel ${orderId}
266-
267-
`);
268-
269-
return;
270-
}
271-
}
272-
default:
273-
return logAndQuit(
274-
`Failed to place order: Unexpected order status: ${res.status}`,
275-
);
276-
}
262+
`);
277263
}
278264
}
279265

0 commit comments

Comments
 (0)