-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
updated accounts restructure, continuing from mixs changes
- Loading branch information
Showing
11 changed files
with
193 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,73 @@ | ||
import inquirer from "inquirer"; | ||
import Entropy from "@entropyxyz/sdk"; | ||
|
||
import { getSelectedAccount, print } from "../common/utils" | ||
import { EntropyAccountConfig, EntropyConfig } from "../config/types"; | ||
import { EntropyAccount } from './main' | ||
import { print } from "src/common/utils" | ||
import * as config from '../config' | ||
|
||
import { | ||
manageAccountsQuestions, | ||
newAccountQuestions, | ||
registerAccount, | ||
selectAccountQuestions | ||
} from "./utils"; | ||
import Entropy from "@entropyxyz/sdk"; | ||
import { EntropyConfig } from "src/config/types"; | ||
} from "./utils" | ||
|
||
|
||
export async function entropyManageAccounts (entropy: Entropy, endpoint: string, storedConfig: EntropyConfig) { | ||
const AccountService = new EntropyAccount(entropy, endpoint) | ||
export async function entropyManageAccounts (endpoint: string, storedConfig: EntropyConfig) { | ||
const AccountService = new EntropyAccount({ endpoint }) | ||
const { accounts } = storedConfig | ||
const { interactionChoice } = await inquirer.prompt(manageAccountsQuestions) | ||
switch (interactionChoice) { | ||
case 'create-import': { | ||
let { seed, name, path, importKey } = await inquirer.prompt(newAccountQuestions) | ||
if (importKey && seed.includes('#debug')) { | ||
// isDebugMode = true | ||
seed = seed.split('#debug')[0] | ||
} | ||
const newAccount = await AccountService.create({ seed, name, path }) | ||
case 'create-import': { | ||
const answers = await inquirer.prompt(newAccountQuestions) | ||
const { name, path, importKey } = answers | ||
let { seed } = answers | ||
if (importKey && seed.includes('#debug')) { | ||
// isDebugMode = true | ||
seed = seed.split('#debug')[0] | ||
} | ||
case 'list-account': { | ||
|
||
const newAccount = await AccountService.create({ seed, name, path }) | ||
accounts.push(newAccount) | ||
return { | ||
accounts, | ||
selectedAccount: newAccount.address | ||
} | ||
case 'select-account': { | ||
|
||
} | ||
case 'select-account': { | ||
const { selectedAccount } = await inquirer.prompt(selectAccountQuestions(accounts)) | ||
|
||
print('Current selected account is ' + selectedAccount) | ||
return { | ||
accounts: storedConfig.accounts, | ||
selectedAccount: selectedAccount.address | ||
} | ||
case 'exit': { | ||
} | ||
case 'list-account': { | ||
const list = this.list(accounts) | ||
list?.forEach((account: EntropyAccountConfig)=> print(account)) | ||
return | ||
} | ||
case 'exit': { | ||
return 'exit' | ||
} | ||
default: | ||
throw new Error('AccountsError: Unknown interaction action') | ||
} | ||
} | ||
|
||
} | ||
export async function entropyRegister (entropy: Entropy, endpoint: string, storedConfig: EntropyConfig): Promise<Partial<EntropyConfig>> { | ||
const AccountService = new EntropyAccount({ entropy, endpoint }) | ||
|
||
const { accounts, selectedAccount } = storedConfig | ||
const currentAccount = getSelectedAccount(accounts, selectedAccount) | ||
if (!currentAccount) { | ||
print("No account selected to register") | ||
return; | ||
} | ||
return { accounts: responses.accounts ? responses.accounts : storedConfig.accounts, selectedAccount: responses.selectedAccount || storedConfig.selectedAccount } | ||
print("Attempting to register the address:", currentAccount.address) | ||
const updatedAccount = await AccountService.registerAccount(currentAccount) | ||
const arrIdx = accounts.indexOf(currentAccount) | ||
accounts.splice(arrIdx, 1, updatedAccount) | ||
print("Your address", updatedAccount.address, "has been successfully registered.") | ||
|
||
return { accounts, selectedAccount } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export interface AccountCreateParams { | ||
name: string | ||
seed: string | ||
seed?: string | ||
path?: string | ||
} | ||
|
||
|
Oops, something went wrong.