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

ext/resources: use standardised frontend messaging #13

Conversation

jamierumbelow
Copy link
Contributor

@jamierumbelow jamierumbelow commented Dec 11, 2021

This PR starts to standardise the messaging format between the different JS files, with the goal of being able to validate and type messages from cradle to grave, from JS to Swift and back again.

Since each component has its own communication method and security policies, this PR introduces a Messenger object that is defined in terms of the component it is in:

const Messenger = getMessenger('background');

This Messenger abstraction knows for a given (source, destination) pair how to send messages, and over which pipeline (either browser.runtime or browser.tabs or window.sendMessage).

Currently, it's not responsible for listening to these messages, though that is a natural next step.

It also:

  • simplifies the view rendering logic
  • removes much of the global state from background, content and popup, preferring a more injected, localised and functional approach
  • adds tab-specific sessionId generation, which is stored in and read from localStorage
  • adds a lot of logging to the frontend code
  • adds a very rough loading state for initial popup load

Explicitly not included in this PR:

  • Unit testing of messaging primatives
  • Standardisation of the JS <-> Swift interface
  • Session-specific network connections

There are probably more things missing, or code that's unclear here. The PR was starting to get big, so I figured it'd be better to merge earlier. Feel free to pop any questions in here / Twist and I'll get back to you soon!

@ronaldmannak
Copy link
Contributor

Thanks Jamie! @natclark @DimitarNestorov can you take a look at the JS/Typescript code?

@DimitarNestorov DimitarNestorov merged commit a2cc3ff into Safari-Wallet:main Dec 23, 2021
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