Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor entropy register so CLI/TUI are similar #242

Merged
merged 2 commits into from
Sep 27, 2024

Conversation

mixmix
Copy link
Contributor

@mixmix mixmix commented Sep 26, 2024

During QA discussion, notice that entropy register was coded the same in CLI + TUI.

This PR:

  • reduces what main does to only be registering on-chain
  • moves entropy config mutation + persistence into util
  • changes command and interaction to use the same 2 functions
    • includes refactor of the command action

const entropy: Entropy = await loadEntropy(accountToRegister.address, endpoint)
const accountService = new EntropyAccount(entropy, endpoint)
const updatedAccount = await accountService.registerAccount(accountToRegister)
// NOTE: loadEntropy throws if it can't find opts.account
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// NOTE: loadEntropy throws if it can't find opts.account
// NOTE: loadEntropy throws if it can't find opts.account
// This is important because we don't want to register if we don't have a place to persist later

@@ -75,28 +76,6 @@ export class EntropyAccount extends EntropyBase {
})
}

// WATCH: should this be extracted to interaction.ts?
async registerAccount (account: EntropyAccountConfig, registerParams?: AccountRegisterParams): Promise<EntropyAccountConfig> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All this function is is registerAndPushKeysIntoAccount

I have pulled this out into the verbosely named util which

  • pushes into account
  • persists config

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also the lgger correct?

export async function addVerifyingKeyToAccountAndSelect (verifyingKey: string, accountNameOrAddress: string) {
const storedConfig = await config.get()
const account = findAccountByAddressOrName(storedConfig.accounts, accountNameOrAddress)
if (!account) throw Error(`Unable to persist verifyingKey "${verifyingKey}" to unknown account "${accountNameOrAddress}"`)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very unlikely because we have earlier checked the account exists...but we put a nice message out anyway 🤷

Alternative.. make a function with an uglier signature (storeConfig, verifyingKey, account) ? 😢 this could still fail if account is not within storedConfig.accounts tho ...

Comment on lines +34 to +37
await config.set({
...storedConfig,
selectedAccount: account.address
})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check my working.

We don't need to any of the fancy slicing or inserting accounts here because:

  • on line 28 : we grab the ref for target account in storedConfig.accounts
  • on line 31 : we push a key into that account's data (mutating it)
  • on line 35 : we say "persist that mutated storedConfig"

@frankiebee frankiebee merged commit f3412d2 into naynay/file-restructure Sep 27, 2024
2 checks passed
@frankiebee frankiebee deleted the mixmix/entropy-register-fix branch September 27, 2024 19:17
@github-actions github-actions bot locked and limited conversation to collaborators Sep 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants