Safari-Wallet / ui

https://safari-wallet-test-dapp.vercel.app
GNU General Public License v3.0
40 stars 11 forks source link

ext/resources: use standardised frontend messaging #13

Closed jamierumbelow closed 2 years ago

jamierumbelow commented 2 years ago

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:

Explicitly not included in this PR:

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 commented 2 years ago

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