-
Notifications
You must be signed in to change notification settings - Fork 273
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
feat: account names #284
Conversation
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. |
Thanks! Will tried to get it cleaned up for review in the next day or two! |
packages/extension/src/ui/components/Account/AccountListItem.tsx
Outdated
Show resolved
Hide resolved
accountNumber: number | ||
address: string | ||
status: WalletStatus | ||
isDeleteable?: boolean | ||
} | ||
|
||
export const AccountListItem: FC<AccountListProps> = ({ | ||
accountName, | ||
accountNumber, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" }}> |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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:
- Keep the data coming from
recovery.ts recover()
(account store before these changes) separate from any user input/metadata - More future proof if there are plans for user's to add more account details.
Cons for separate stores:
- UI components would need to use multiple stores to show all the data for an account
return selectedWallet ? wallets[selectedWallet] : undefined | ||
} | ||
|
||
const calcAccountNumber = ( |
There was a problem hiding this comment.
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 | ||
) | ||
} |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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,
},
},
@@ -34,6 +34,7 @@ export const recover = async ({ | |||
.map(({ address, network }) => new Wallet(address, network)) | |||
.reduce((acc, wallet) => ({ ...acc, [wallet.address]: wallet }), {}) | |||
|
|||
setAccountNamesFromBackup(wallets) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
packages/extension/src/ui/Wallet.ts
Outdated
@@ -11,13 +11,20 @@ const ArgentCompiledContractJson: CompiledContract = json.parse( | |||
export class Wallet { | |||
address: string | |||
networkId: string | |||
name?: string |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
?
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! |
Good to hear. Yeah go for it! I don't have any unpushed work. |
c3162d4
to
8ae5133
Compare
@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}`)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (const [address, account] of Object.entries(accounts)) { | ||
const { networkId } = account | ||
if (!accountNames?.[networkId]?.[address]) { | ||
const name = getDefaultAccountName(account) |
There was a problem hiding this comment.
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
@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 |
@delaaxe just tested it out. looks good to me! |
Implements #263
Needs cleanup once overall UI flow and functionality is approved.
account_names1.mp4
account_names2.mp4