Skip to content

Commit

Permalink
feat(crypto fund): init confirmation promot PE-6732
Browse files Browse the repository at this point in the history
  • Loading branch information
fedellen committed Sep 12, 2024
1 parent 153eec6 commit 3714599
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"ethers": "^6.12.0",
"mime-types": "^2.1.35",
"plimit-lit": "^3.0.1",
"prompts": "^2.4.2",
"tweetnacl": "^1.0.3",
"winston": "^3.14.1"
},
Expand All @@ -106,6 +107,7 @@
"@types/mime-types": "^2.1.4",
"@types/mocha": "^10.0.1",
"@types/node": "^20.4.8",
"@types/prompts": "^2.4.9",
"@types/sinon": "^10.0.15",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^6.4.0",
Expand Down
24 changes: 23 additions & 1 deletion src/cli/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
import { exec } from 'node:child_process';
import { createReadStream, statSync } from 'node:fs';
import prompts from 'prompts';

import {
TurboFactory,
Expand Down Expand Up @@ -100,9 +101,30 @@ export async function cryptoFund(options: CryptoFundOptions) {
const turbo = await turboFromOptions(options);

const token = tokenFromOptions(options);
const tokenAmount = tokenToBaseMap[token](value);

const { winc } = await turbo.getWincForToken({ tokenAmount });

if (!options.skipConfirmation) {
const { confirm } = await prompts({
type: 'confirm',
name: 'confirm',
message: `This command will send a payment transaction for ${value} ${token} to the connected bundler's wallet in exchange for ~${(
+winc / 1_000_000_000_000
).toFixed(
12,
)} Credits. This is in addition to any typical gas fees on the given network. Would you like to proceed with this funding?`,
initial: true,
});

if (!confirm) {
console.log('Aborted crypto fund transaction');
return;
}
}

const result = await turbo.topUpWithTokens({
tokenAmount: tokenToBaseMap[token](value),
tokenAmount,
});

console.log(
Expand Down
6 changes: 6 additions & 0 deletions src/cli/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export const optionMap = {
description: 'Disable logging',
default: false,
},
skipConfirmation: {
alias: '--skip-confirmation',
description: 'Skip all confirmation prompts',
default: false,
},
folderPath: {
alias: '-f, --folder-path <folderPath>',
description: 'Directory to upload',
Expand Down Expand Up @@ -115,6 +120,7 @@ export const globalOptions = [
optionMap.debug,
optionMap.quiet,
optionMap.token,
optionMap.skipConfirmation,
];

export const uploadFolderOptions = [
Expand Down
1 change: 1 addition & 0 deletions src/cli/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type GlobalOptions = {
gateway: string | undefined;
debug: boolean;
quiet: boolean;
skipConfirmation: boolean;
token: string;
};

Expand Down
26 changes: 26 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1859,6 +1859,14 @@
resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
integrity sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==

"@types/prompts@^2.4.9":
version "2.4.9"
resolved "https://registry.yarnpkg.com/@types/prompts/-/prompts-2.4.9.tgz#8775a31e40ad227af511aa0d7f19a044ccbd371e"
integrity sha512-qTxFi6Buiu8+50/+3DGIWLHM6QuWsEKugJnnP6iv2Mc4ncxE4A/OJkjuVOA+5X0X1S/nq5VJRa8Lu+nwcvbrKA==
dependencies:
"@types/node" "*"
kleur "^3.0.3"

"@types/semver@^7.3.12":
version "7.5.1"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.1.tgz#0480eeb7221eb9bc398ad7432c9d7e14b1a5a367"
Expand Down Expand Up @@ -5276,6 +5284,11 @@ kind-of@^6.0.3:
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==

kleur@^3.0.3:
version "3.0.3"
resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e"
integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==

kuler@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/kuler/-/kuler-2.0.0.tgz#e2c570a3800388fb44407e851531c1d670b061b3"
Expand Down Expand Up @@ -6764,6 +6777,14 @@ promise-retry@^2.0.1:
err-code "^2.0.2"
retry "^0.12.0"

prompts@^2.4.2:
version "2.4.2"
resolved "https://registry.yarnpkg.com/prompts/-/prompts-2.4.2.tgz#7b57e73b3a48029ad10ebd44f74b01722a4cb069"
integrity sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==
dependencies:
kleur "^3.0.3"
sisteransi "^1.0.5"

promzard@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/promzard/-/promzard-1.0.0.tgz#3246f8e6c9895a77c0549cefb65828ac0f6c006b"
Expand Down Expand Up @@ -7376,6 +7397,11 @@ sinon@^15.2.0:
nise "^5.1.4"
supports-color "^7.2.0"

sisteransi@^1.0.5:
version "1.0.5"
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==

slash@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634"
Expand Down

0 comments on commit 3714599

Please sign in to comment.