From 58fea0592768858fab16340d76be236c2c638d22 Mon Sep 17 00:00:00 2001 From: "Gomez Goiri, Aitor" <aitor.gomez@tecnalia.com> Date: Wed, 2 Mar 2022 17:13:00 +0100 Subject: [PATCH] Accepting user input to specify first bid amount --- apps/batch-sim/index.js | 15 +++++++++++---- apps/cement-cli/lib.js | 7 ++++--- apps/sidenor-cli/lib.js | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/batch-sim/index.js b/apps/batch-sim/index.js index f154158..3aa9750 100644 --- a/apps/batch-sim/index.js +++ b/apps/batch-sim/index.js @@ -41,16 +41,23 @@ const simulateCycle = async (arg1, cmd) => { batchId = await createAssetAndSendToCone(apiClient, "simulated asset 2") batchId = await createAssetAndSendToCone(apiClient, "simulated asset 3") - const stockId = await sendToStock(apiClient, { assetId: batchId }) + const selectedStock = await sendToStock(apiClient, { assetId: batchId }) await signInAs(apiClient, otherArgs.cement1User, password) - await bidAsset(apiClient, { assetId: stockId, quantity: 1000, price: 2 }) + await bidAsset(apiClient, { + assetId: selectedStock.id, + price: 2 + }) await signInAs(apiClient, otherArgs.cement2User, password) - await bidAsset(apiClient, { assetId: stockId, quantity: 500, price: 3 }) + await bidAsset(apiClient, { + assetId: selectedStock.id, + quantity: selectedStock.quantity - 500, + price: 3 + }) await signInAs(apiClient, otherArgs.sidenorUser, password) - await acceptBid(apiClient, { assetId: stockId }) + await acceptBid(apiClient, { assetId: selectedStock.id }) } const program = createCLIApp() diff --git a/apps/cement-cli/lib.js b/apps/cement-cli/lib.js index d76da19..6f1b0a4 100644 --- a/apps/cement-cli/lib.js +++ b/apps/cement-cli/lib.js @@ -11,6 +11,7 @@ const bidAsset = async ( const biddableAssets = await apiClient.getBiddableAssets() const assetId = paramAssetId || (await promptAssetSelection(biddableAssets)) + const assetToBid = biddableAssets.find(({ id }) => id === assetId) let chosenQuantity = quantity if (!quantity) { @@ -18,19 +19,19 @@ const bidAsset = async ( { type: "number", name: "inputQuantity", - message: "Choose an ammount of slag" + message: `Choose an ammount of slag (in ${assetToBid.units}, max ${assetToBid.quantity}):` } ]) chosenQuantity = inputQuantity } let chosenPrice = price - if (!quantity) { + if (!price) { const { inputPrice } = await inquirer.prompt([ { type: "number", name: "inputPrice", - message: "Provide the offered price" + message: "Provide the offered price (in €):" } ]) chosenPrice = inputPrice diff --git a/apps/sidenor-cli/lib.js b/apps/sidenor-cli/lib.js index 1e87a82..4e6fd7a 100644 --- a/apps/sidenor-cli/lib.js +++ b/apps/sidenor-cli/lib.js @@ -169,7 +169,7 @@ const sendToStock = async (apiClient, { assetId: paramAssetId }) => { console.log("Moved to stock", newStockAsset.id) - return newStockAsset.id + return newStockAsset } const bidResponse = -- GitLab