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: avatar plugin #11473

Merged
merged 8 commits into from Apr 24, 2024
Merged

refactor: avatar plugin #11473

merged 8 commits into from Apr 24, 2024

Conversation

guanbinrui
Copy link
Member

@guanbinrui guanbinrui commented Mar 2, 2024

Description

Closes MF-6073

Type of change

  • Documentation
  • Code refactoring (Restructuring existing code w/o changing its observable behavior)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (a fix or feature that would make something no longer possible to do/require old user must upgrade their Mask Network to this new version)

Previews

Checklist

  • My code follows the style guidelines of this project.
  • I have performed a self-review of my own code.
    • I have removed all in development console.logs
    • I have removed all commented code.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have read Internationalization Guide and moved text fields to the i18n JSON file.

If this PR depends on external APIs:

  • I have configured those APIs with CORS headers to let extension requests get passed.
    • chrome extension: chrome-extension://[id]
    • firefox extension: moz-extension://[id]
  • I have delegated all web requests to the background service via the internal RPC bridge.

@guanbinrui guanbinrui added this to the 2.24.6 milestone Mar 2, 2024
@guanbinrui guanbinrui force-pushed the refactor/avatar-plugin branch 12 times, most recently from d428df5 to 282baaa Compare March 9, 2024 03:42
@guanbinrui guanbinrui force-pushed the refactor/avatar-plugin branch 5 times, most recently from 7f93455 to 0d8282a Compare March 9, 2024 12:33
Base automatically changed from hotfix/2.24.6 to released March 29, 2024 07:09
refactor: remove unused components

chore: tidy up components

refactor: store helpers

chore: impl store

refactor: avatar components

refactor: cleanup types

refactor: remove mobile sniffing
@guanbinrui guanbinrui changed the base branch from released to release/2.25.0 April 24, 2024 12:51
@guanbinrui guanbinrui marked this pull request as ready for review April 24, 2024 14:53
Comment on lines +247 to +248
const indexOf = url.indexOf('?')
return url.slice(0, Math.max(0, indexOf === -1 ? url.length : indexOf))
Copy link
Member

Choose a reason for hiding this comment

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

why you don't use new URL()??

Copy link
Member Author

Choose a reason for hiding this comment

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

private getAvatarToken = memoizePromise(
memoize,
(userId: string, avatarId?: string, publicKey?: string): Promise<StoreItem | null> => {
return requestIdleCallbackAsync(async () => {
Copy link
Member

Choose a reason for hiding this comment

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

what will happen if you don't use this requestIdleCallback? why do you need it?

Copy link
Member Author

Choose a reason for hiding this comment

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

The result of the callback function doesn't need to be used immediately.

Copy link
Member

Choose a reason for hiding this comment

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

The result of the callback function doesn't need to be used immediately.

sorry can you clarify? I don't understand

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 created a data hub to store avatar records. It accepts data fetch requests from the UI in various places. When it receives a request, it fetches data when the browser is idle, because the quantity of requests might be quite high. I don't want this task to block the UI.

Copy link
Member

Choose a reason for hiding this comment

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

but you are not queueing them. so it will block the UI next time you have idle

@@ -0,0 +1,21 @@
import { type StoreAPI } from '../types/Store.js'

export abstract class StoreProvider<T> implements StoreAPI.Provider<T> {
Copy link
Member

Choose a reason for hiding this comment

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

in case you're referring to React's API (which also has a getSnapshot), you cannot store mutable objects in it, or you have to do a full-clone in the getSnapshot

Copy link
Member Author

Choose a reason for hiding this comment

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

It's consumed by useExternalStore. I stored an instance of this class, which is created once and doesn't change. The one thing that might break the rule is that the instance contains a mutable map. However, since this is used internally, I think it's fine.

Copy link
Member

Choose a reason for hiding this comment

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

The one thing that might break the rule is that the instance contains a mutable map.

well, this is wrong.

getSnapshot() { return structuredClone(this.store) }

you can do this, if this.store does not store a custom class. things like Map<string, string> is ok

Copy link
Member Author

Choose a reason for hiding this comment

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

So each time the getSnapshot() is invoked, a new instance of Store class should be returned?

Copy link
Member

Choose a reason for hiding this comment

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

So each time the getSnapshot() is invoked, a new instance of Store class should be returned?

No, it should return what it stored. The store itself is untouched.

@guanbinrui guanbinrui merged commit d6e59ec into release/2.25.0 Apr 24, 2024
3 checks passed
@guanbinrui guanbinrui deleted the refactor/avatar-plugin branch April 24, 2024 16:49
guanbinrui added a commit that referenced this pull request Apr 29, 2024
* chore: bump version to 2.25.0

* fix: setting list (#11556)

* fix: swap page in dark mode (#11555)

* fix: bugfix for swap settings list

* fix: scroll

* chore: replace lens profile link (#11557)

* fix: replace lens profile link

* chore: name

* fix: remove edit profile

* fix: swap get gas alert (#11559)

* fix: conflict

* fix: scroll and metis token value (#11584)

* fix: mf-6168 reset connection error (#11579)

* fix: bugfix for exchange ui (#11586)

* fix: selecting token from other chain set it to native token (#11587)

* fix: mf-6195 selecting token from other chain set it to native token

* fix: mf-6193 background of redpacket history

* fix: repalce lens link (#11588)

* fix: bugfix for switch logo button (#11589)

* refactor: avatar plugin (#11473)

* refactor: avatar

refactor: remove unused components

chore: tidy up components

refactor: store helpers

chore: impl store

refactor: avatar components

refactor: cleanup types

refactor: remove mobile sniffing

* fix: eslint

* refactor: cleanup

* refactor: code style

* fix: smoke testing

* fix: warning

* fix: test case

* fix: eslint

---------

Co-authored-by: guanbinrui <guanbinrui@users.noreply.github.com>

* fix: mf-6201 crash caused by mui (#11592)

* fix: missing chain (#11593)

* fix: set max number for chain select (#11595)

* fix: invoke redpacket parsing api on Firefly only (#11594)

* fix: profile avatar (#11596)

* fix: profile avatar

* fix: lint error

* fix: mf-6200 nft avatar decoration (#11598)

* chore: add lens handle name fallback (#11601)

* fix: uniq binding account (#11602)

* chore: lock file

---------

Co-authored-by: nuanyang233 <nuanyang233@gmail.com>
Co-authored-by: Jack Works <jackworks@protonmail.com>
Co-authored-by: Wukong Sun <158803171+swkatmask@users.noreply.github.com>
Co-authored-by: guanbinrui <guanbinrui@users.noreply.github.com>
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

2 participants