fix(generate): use Duff, not Dash... uhg 🤦‍♂️
[crowdnode.js/.git] / bin / crowdnode.js
index a093452a9ef72a7535885af0cb605309fe2d453d..943eaa83ad6f071ca534a5b3f97d8765f674e59c 100755 (executable)
@@ -192,7 +192,8 @@ async function main() {
   // deposit if balance is over 100,000 (0.00100000)
   process.stdout.write("Checking balance... ");
   let balanceInfo = await dashApi.getInstantBalance(pub);
-  console.info(`${balanceInfo.balanceSat} (Đ${balanceInfo.balance})`);
+  let balanceDash = toDash(balanceInfo.balanceSat);
+  console.info(`${balanceInfo.balanceSat} (Đ${balanceDash})`);
   /*
   let balanceInfo = await insightApi.getBalance(pub);
   if (balanceInfo.unconfirmedBalanceSat || balanceInfo.unconfirmedAppearances) {
@@ -300,11 +301,14 @@ async function generate(name) {
     note = `\n(for pubkey address ${pub})`;
   }
 
+  let testDash = 0.01;
+  let testDuff = toDuff(testDash);
+
   let err = await Fs.access(filepath).catch(Object);
   if (!err) {
     // TODO show QR anyway
     //wif = await Fs.readFile(filepath, 'utf8')
-    //showQr(pub, 0.01);
+    //showQr(pub, testDuff);
     console.info(`'${filepath}' already exists (will not overwrite)`);
     process.exit(0);
     return;
@@ -313,13 +317,13 @@ async function generate(name) {
   await Fs.writeFile(filepath, wif, "utf8").then(function () {
     console.info(``);
     console.info(
-      `Use the QR Code below to load a test deposit of Đ0.01 onto your staking key.`,
+      `Use the QR Code below to load a test deposit of Đ${testDash} onto your staking key.`,
     );
     console.info(``);
-    showQr(pub, 0.01);
+    showQr(pub, testDuff);
     console.info(``);
     console.info(
-      `Use the QR Code above to load a test deposit of Đ0.01 onto your staking key.`,
+      `Use the QR Code above to load a test deposit of Đ${testDash} onto your staking key.`,
     );
     console.info(``);
     console.info(`Generated ${filepath} ${note}`);
@@ -345,8 +349,9 @@ async function transfer(args, state) {
     tx = await state.dashApi.createBalanceTransfer(state.privKey, newAddr);
   }
   if (duffAmount) {
+    let dashAmountStr = toDash(duffAmount);
     console.info(
-      `Transferring ${duffAmount} (Đ${dashAmount}) to ${newAddr}...`,
+      `Transferring ${duffAmount} (Đ${dashAmountStr}) to ${newAddr}...`,
     );
   } else {
     console.info(`Transferring balance to ${newAddr}...`);
@@ -487,9 +492,6 @@ async function deposit(args, state) {
     effectiveAmount = state.balanceInfo.balanceSat - reserve;
   }
 
-  console.info(
-    `(holding ${reserve} (Đ${reserveDash}) in reserve for API calls)`,
-  );
   let effectiveDash = toDash(effectiveAmount);
   console.info(
     `Initiating deposit of ${effectiveAmount} (Đ${effectiveDash})...`,
@@ -569,7 +571,7 @@ async function wifFileToAddr(keyfile) {
 async function collectSignupFees(insightBaseUrl, pub) {
   showQr(pub);
 
-  let signupTotalDash = (signupTotal / DUFFS).toFixed(8);
+  let signupTotalDash = toDash(signupTotal);
   let signupMsg = `Please send >= ${signupTotal} (Đ${signupTotalDash}) to Sign Up to CrowdNode`;
   let msgPad = Math.ceil((qrWidth - signupMsg.length) / 2);
   let subMsg = "(plus whatever you'd like to deposit)";
@@ -614,6 +616,10 @@ function toDash(duffs) {
   return (duffs / DUFFS).toFixed(8);
 }
 
+function toDuff(dash) {
+  return Math.round(parseFloat(dash) * DUFFS);
+}
+
 // Run
 
 main().catch(function (err) {