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

Remove global walletId and index accounts by address #1019

Merged
merged 1 commit into from
Sep 23, 2022

Conversation

lukaw3d
Copy link
Member

@lukaw3d lukaw3d commented Sep 22, 2022

Motivation: let walletId = 0 is annoying to add to persisted state

@github-actions
Copy link

github-actions bot commented Sep 22, 2022

MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ EDITORCONFIG editorconfig-checker 15 0 0.04s
✅ GIT git_diff yes no 0.01s
✅ TSX eslint 8 0 0 7.17s
✅ TYPESCRIPT eslint 7 0 0 7.08s

See errors details in artifact MegaLinter reports on CI Job page
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

@codecov
Copy link

codecov bot commented Sep 22, 2022

Codecov Report

Merging #1019 (0186a14) into master (ac76ab1) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1019      +/-   ##
==========================================
- Coverage   88.57%   88.55%   -0.02%     
==========================================
  Files         101      101              
  Lines        1750     1747       -3     
  Branches      405      403       -2     
==========================================
- Hits         1550     1547       -3     
  Misses        200      200              
Flag Coverage Δ
cypress 60.62% <100.00%> (-0.07%) ⬇️
jest 78.78% <70.58%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ponents/Toolbar/Features/AccountSelector/index.tsx 100.00% <100.00%> (ø)
src/app/components/TransactionModal/index.tsx 91.66% <100.00%> (ø)
...ge/Features/ImportAccountsSelectionModal/index.tsx 96.55% <100.00%> (+0.12%) ⬆️
src/app/state/wallet/index.ts 78.94% <100.00%> (ø)
src/app/state/wallet/saga.ts 98.33% <100.00%> (-0.06%) ⬇️
src/app/state/wallet/selectors.ts 100.00% <100.00%> (ø)
src/app/useRouteRedirects.tsx 100.00% <100.00%> (ø)

selectedWallet?: number
wallets: { [id: number]: Wallet }
selectedWallet?: string
wallets: { [address: string]: Wallet }
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of using { [address: string]: Wallet } I find the Record<string, Wallet> form easier to read.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the key name address is helpful here. Too many things are a string

Copy link
Contributor

Choose a reason for hiding this comment

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

That's true. In fact it's so true that I would consider adding export type Address = string somewhere, and then consistently using Address instead of string wherever we are talking about addresses. (But that's a story of a different PR.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah :D would we consistently use it tho? maybe :D

If we add it, we should alias it like StringifiedBigInt, or make it branded

/** Redux can't serialize bigint fields, so we stringify them, and mark them. */
export type StringifiedBigInt = string & PreserveAliasName
interface PreserveAliasName extends String {}

Copy link
Contributor

@csillag csillag left a comment

Choose a reason for hiding this comment

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

Reviewed. LGTM.

(Almost feels like it should have been written like this from the start.)

},
addWallet(state, action: PayloadAction<AddWalletPayload>) {},
walletOpened(state, action: PayloadAction<Wallet>) {
const newWallet = action.payload
state.wallets[newWallet.id] = Object.assign({}, newWallet)
state.wallets[newWallet.address] = { ...newWallet }
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm I thought immer takes care of immutability and there is no need to use spread operator or Object.assign when assigning an object to state.

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright I'll risk it :D

@lukaw3d lukaw3d merged commit 3b53299 into master Sep 23, 2022
@lukaw3d lukaw3d deleted the lw/index-accounts branch September 23, 2022 17:26
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.

None yet

3 participants