UNPKG

sui-direct

Version:

Decentralized version control system on SUI blockchain

83 lines (82 loc) 3.36 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.authCommands = authCommands; const auth_1 = __importDefault(require("../lib/auth")); const wallet_1 = __importDefault(require("../lib/wallet")); const colors_1 = require("../utils/colors"); const helpers_1 = require("../utils/helpers"); function authCommands(program, p2p) { const auth = program.command("auth"); auth.command("login") .description("Login to the service") .option("-w, --wallet <string>", "Wallet address of your SUI wallet") .action(async (options) => { (0, helpers_1.p2pStarter)(p2p) .then(async (_) => { const authInstance = new auth_1.default(_); await authInstance.login(options === null || options === void 0 ? void 0 : options.wallet); return process.exit(0); }) .catch(error => { if (error) { console.log(colors_1.colorize.errorIcon("An error occurred.")); console.error(colors_1.colorize.error(error)); } }) .finally(() => { process.exit(1); }); }); auth.command("logout") .description("Logout from the service") .action(async () => { (0, helpers_1.p2pStarter)(p2p).then(_ => { const authInstance = new auth_1.default(_); authInstance.getUser() .then(async () => { authInstance.logout(); console.log(colors_1.colorize.successIcon("Successfully logged out.")); return process.exit(0); }) .catch(error => { if (error) { console.log(colors_1.colorize.errorIcon("An error occurred.")); console.error(colors_1.colorize.error(error)); } }) .finally(() => { process.exit(1); }); }); }); auth.command("balance") .description("Check account balance") .action(() => { (0, helpers_1.p2pStarter)(p2p).then(_ => { const authInstance = new auth_1.default(_); authInstance.getUser() .then(async (user) => { const wallet = new wallet_1.default(user.data.deposit); const { WAL, SUI } = await wallet.getBalance(); const normalizedSUI = Number(SUI.totalBalance) / 1e9; const normalizedWAL = Number(WAL.totalBalance) / 1e9; console.log(`Coin balances of ${colors_1.colorize.warning(user.data.deposit)}\n`); console.log(`SUI: ${colors_1.colorize.highlight(normalizedSUI.toString())}\n` + `WAL: ${colors_1.colorize.highlight(normalizedWAL.toString())}`); return process.exit(0); }) .catch(error => { if (error) { console.log(colors_1.colorize.errorIcon("An error occurred.")); console.error(colors_1.colorize.error(error)); } }) .finally(() => { process.exit(1); }); }); }); }