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

feat: account names #284

Merged
merged 12 commits into from
Feb 24, 2022
Merged

Conversation

jgresham
Copy link
Contributor

Implements #263
Needs cleanup once overall UI flow and functionality is approved.

account_names1.mp4
account_names2.mp4

@delaaxe
Copy link
Contributor

delaaxe commented Feb 14, 2022

Thanks for you contribution John, this is great! Small nitpick: it seems that when toggling edit mode, everything that's below the name shifts vertically by 1px. Possible to keep it all fixed?

Also, let me know when you think it's ready so I can review the code.

@jgresham
Copy link
Contributor Author

Thanks! Will tried to get it cleaned up for review in the next day or two!

@jgresham
Copy link
Contributor Author

jgresham commented Feb 19, 2022

@delaaxe fixed the 1px UI shifting bug and cleaned up the PR.

wallet/account naming seems mixed but there is an issue for that #311

note: this is separate from starknet's cli --account=my_account

@jgresham jgresham changed the title (WIP) feat: account names feat: account names Feb 19, 2022
accountNumber: number
address: string
status: WalletStatus
isDeleteable?: boolean
}

export const AccountListItem: FC<AccountListProps> = ({
accountName,
accountNumber,
Copy link
Contributor

Choose a reason for hiding this comment

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

accountNumber shouldn't be needed anymore with this change

@@ -34,18 +34,33 @@ interface AccountSubheaderProps {
networkId: string
status: WalletStatus
accountNumber: number
Copy link
Contributor

Choose a reason for hiding this comment

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

same here and also everywhere below

}) => (
<>
<div>
<AccountName>{getAccountName(accountNumber)}</AccountName>
<div style={{ display: "flex", flexDirection: "column" }}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Try avoiding inline styles as much as possible

...state.wallets,
[newWallet.address]: newWallet,
export const useAccount = create<AccountStore>(
persist(
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't it be cleaner to do a separate store that's persisted for account names and potentially other data, maybe AccountDetails or AccountMetadata, instead of wrapping this whole store just to make one field persistent?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it could be cleaner and easier to reason about where the data is coming from. I kept in account store because I thought it would be less changes elsewhere. Few thoughts:

Pros for separate stores:

  1. Keep the data coming from recovery.ts recover() (account store before these changes) separate from any user input/metadata
  2. More future proof if there are plans for user's to add more account details.

Cons for separate stores:

  1. UI components would need to use multiple stores to show all the data for an account

return selectedWallet ? wallets[selectedWallet] : undefined
}

const calcAccountNumber = (
Copy link
Contributor

Choose a reason for hiding this comment

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

please avoid abbreviations and acronyms as much as possible

return (
Object.keys(wallets).findIndex((address) => address === accountAddress) + 1
)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this should be more along the lines of:

index = 1
while getDefaultAccountName(index) not in accountNames:
  index++
return getDefaultAccountName(index)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think this would work with the structure of accountNames being:
https://github.com/argentlabs/argent-x/pull/284/files#diff-7b1dbae5fd43e7fa9c15da5204f37abd705b208adc0be83178e26bcd3816c32dR48-R54

accountNames: {
              ...state.accountNames,
              [networkId]: {
                ...state.accountNames[networkId],
                [address]: name,
              },
            },

packages/extension/src/ui/utils/wallets.ts Outdated Show resolved Hide resolved
@@ -34,6 +34,7 @@ export const recover = async ({
.map(({ address, network }) => new Wallet(address, network))
.reduce((acc, wallet) => ({ ...acc, [wallet.address]: wallet }), {})

setAccountNamesFromBackup(wallets)
Copy link
Contributor

Choose a reason for hiding this comment

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

this function wouldn't be needed if there was a single source of truth for account names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct, but would need to add an additional "useStore" to UI components.

@@ -11,13 +11,20 @@ const ArgentCompiledContractJson: CompiledContract = json.parse(
export class Wallet {
address: string
networkId: string
name?: string
Copy link
Contributor

Choose a reason for hiding this comment

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

this field shouldn't exist on this class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not aware how Wallet and Account is used with starknet. Is this class better named Account?

@delaaxe
Copy link
Contributor

delaaxe commented Feb 22, 2022

we'll try to include this in a minor release for the end of week, so if you don't have time to go through the changes, I hope you won't mind if I do them myself!

@jgresham
Copy link
Contributor Author

Good to hear. Yeah go for it! I don't have any unpushed work.

@delaaxe
Copy link
Contributor

delaaxe commented Feb 23, 2022

@jgresham I've made the changes. Do you see anything that could be wrong or that I might've missed before I merge? Thanks again for your help

useAccountMetadata.getState().accountNames[account.networkId] || {},
)
let index = 1
while (names.includes(`Account ${index}`)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this method of determining the default account name has a bug. On first open of my wallet, all accounts had "Account 1" as the name. Also, my opinion is that the n-th account should be named Account n, regardless of the other account names.
account-numbers

for (const [address, account] of Object.entries(accounts)) {
const { networkId } = account
if (!accountNames?.[networkId]?.[address]) {
const name = getDefaultAccountName(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.

names may need to be passed in here as the state isn't updated for each iteration in getDefaultAccountName

@delaaxe
Copy link
Contributor

delaaxe commented Feb 23, 2022

@jgresham just reverted it to the way you did it before. seeing any more issues?

@jgresham
Copy link
Contributor Author

@jgresham just reverted it to the way you did it before. seeing any more issues?

I don't see any new commits?

@delaaxe
Copy link
Contributor

delaaxe commented Feb 23, 2022

@jgresham just reverted it to the way you did it before. seeing any more issues?

I don't see any new commits?

sorry I pushed to wrong branch. should be ok now

@jgresham
Copy link
Contributor Author

@delaaxe just tested it out. looks good to me!

@delaaxe delaaxe merged commit 7e59127 into argentlabs:main Feb 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants