-
Notifications
You must be signed in to change notification settings - Fork 81
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
Library mode (direct import) and config overhaul #1715
Comments
@aadam-10 @artursapek I came to create an issue requesting this but happened to stumble on this existing one. +1 for this feature. In order to accommodate my DApp's CSP header, the WormholeConnect must be bundled and served from my app's codebase like a regular react lib. It would also be great if the widget could somehow share a wallet connection with the parent app, but I realize that's complex. Any estimate on when this would be available? |
@jmrossy it's still in beta, but you can try it now: 0.3.0-beta.5-development |
Tl;dr
wormhole-connect-loader
is going bye-byeDescription and context
This ticket represents a large change to the code base. There are two main goals behind it:
Neither of these is possible today due to how Connect is published and how it reads its config from the DOM.
Implementation Details
The first goal, dynamic config, requires a change to how Connect gets its custom config.. The original Connect code expected the config to be a stringified JSON object in the
config
attribute on thewormhole-connect
element. This gets parsed when theconfig.ts
file is first evaluated by the browser, and is static from then on.This makes it impossible to use Connect as a component in a React app, because it expects a specific DOM node to exist before React even starts running.
We are moving to the config & theme being passed as props to the top level component:
The theme is no longer a part of the config, it's a separate prop altogether. The component no longer expects these to be hard-coded into the DOM.
For now, we will still disallow updates to the config during runtime because this can cause lots of weird, broken behavior. For example, switching from
testnet
tomainnet
mid-transfer causes Connect to get very confused.This first change enables the second change: allowing apps to import Connect itself as a component from NPM. Importing Connect this way will no longer load the "loader" which merely injects unpkg.com tags into your HTML. It will actually import the Connect component itself.
wormhole-connect-loader
, which exists for the sole purpose of exporting a React component which simply injects two HTML tags loading Connect from unpkg.com, is being taken out back.We will still support the HTML copy-pasta approach of integrating Connect for people not using React.
Code Base Implications
Config imports
The main disruptive aspect of this change is how we use
config
. Before this change, the config was exported bysrc/config/index.ts
as dozens of all-caps consts like:Instead, we will export a single object called
config
and the code base will import that, and refer toconfig.routes
as opposed to justROUTES
.Duplicate React
Today, any website which uses React and also uses Connect is making their users load React twice (since it's in the Connect bundle). That sucks! This ticket will eliminate that problem.
The text was updated successfully, but these errors were encountered: