@@ -36,25 +36,22 @@ import {
36
36
Typography ,
37
37
useMediaQuery ,
38
38
} from "@mui/material" ;
39
- import WormholeBridge , {
39
+ import WormholeConnect , {
40
40
ChainName ,
41
41
MAINNET_CHAINS ,
42
- MainnetChainName ,
43
- Rpcs ,
44
42
TESTNET_CHAINS ,
45
- TestnetChainName ,
46
- Theme ,
47
43
WormholeConnectConfig ,
48
- defaultTheme ,
44
+ dark ,
45
+ CONFIG ,
49
46
} from "@wormhole-foundation/wormhole-connect" ;
47
+ import type { CustomTheme } from "@wormhole-foundation/wormhole-connect" ;
48
+
50
49
import { useCallback , useEffect , useMemo , useState } from "react" ;
51
50
import { useDebounce } from "use-debounce" ;
52
51
import Background from "./Background" ;
53
52
import ColorPicker from "./components/ColorPicker" ;
54
53
import RouteCard from "./components/RouteCard" ;
55
54
import {
56
- DEFAULT_MAINNET_RPCS ,
57
- DEFAULT_TESTNET_RPCS ,
58
55
MAINNET_TOKEN_KEYS ,
59
56
NETWORKS ,
60
57
ROUTE_INFOS ,
@@ -66,7 +63,13 @@ import {
66
63
setObjectPathImmutable ,
67
64
} from "./utils" ;
68
65
69
- const version = "0.2.6" ;
66
+ export type MainnetChainName = keyof typeof MAINNET_CHAINS ;
67
+ export type TestnetChainName = keyof typeof TESTNET_CHAINS ;
68
+ export type Rpcs = {
69
+ [ chain in ChainName ] ?: string ;
70
+ } ;
71
+
72
+ const version = "0.3.0" ;
70
73
// generated with https://www.srihash.org/
71
74
const versionScriptIntegrity =
72
75
"sha384-QOTWWlgPEcpWnzakQRaUW71dYatQWsRJYtCjz+y94hwZxjxg9jU7X+sE6pDmo6Ao" ;
@@ -165,7 +168,7 @@ const ScreenButton = ({
165
168
) ;
166
169
} ;
167
170
168
- const customized = defaultTheme ;
171
+ const customized = dark ;
169
172
customized . background . default = "transparent" ;
170
173
const defaultThemeJSON = JSON . stringify ( customized , undefined , 2 ) ;
171
174
@@ -215,17 +218,16 @@ function App() {
215
218
} ;
216
219
}
217
220
} , [ debouncedFontHref ] ) ;
218
- const [ _customTheme , setCustomTheme ] = useState < Theme | undefined > ( undefined ) ;
219
- const [ debouncedCustomTheme ] = useDebounce ( _customTheme , 1000 ) ;
220
- const customTheme =
221
- _customTheme === undefined ? undefined : debouncedCustomTheme ;
221
+ const [ customTheme , setCustomTheme ] = useState < CustomTheme | undefined > (
222
+ undefined
223
+ ) ;
222
224
const [ customThemeText , setCustomThemeText ] = useState ( defaultThemeJSON ) ;
223
225
// const [customThemeError, setCustomThemeError] = useState<boolean>(false);
224
226
const handleModeChange = useCallback (
225
227
( e : any , value : string ) => {
226
228
if ( value === "dark" || value === "light" ) {
227
229
setMode ( value ) ;
228
- setCustomTheme ( undefined ) ;
230
+ setCustomTheme ( { mode : value } ) ;
229
231
} else {
230
232
setMode ( undefined ) ;
231
233
try {
@@ -458,16 +460,14 @@ function App() {
458
460
} ,
459
461
[ ]
460
462
) ;
461
- // NOTE: the WormholeBridge component is keyed by the stringified version of config
463
+ // NOTE: the WormholeConnect component is keyed by the stringified version of config
462
464
// because otherwise the component did not update on changes
463
465
const config : WormholeConnectConfig = useMemo (
464
466
( ) => ( {
465
467
env : "testnet" , // always testnet for the builder
466
468
rpcs : testnetRpcs ,
467
469
networks : testnetNetworks , // always testnet for the builder
468
470
tokens : testnetTokens , // always testnet for the builder
469
- mode,
470
- customTheme,
471
471
cta :
472
472
ctaText && ctaLink
473
473
? {
@@ -495,8 +495,6 @@ function App() {
495
495
testnetRpcs ,
496
496
testnetNetworks ,
497
497
testnetTokens ,
498
- mode ,
499
- customTheme ,
500
498
ctaText ,
501
499
ctaLink ,
502
500
defaultFromNetwork ,
@@ -516,7 +514,7 @@ function App() {
516
514
const realConfig = { ...config , env, rpcs, networks, tokens } ;
517
515
const realConfigString = JSON . stringify ( realConfig ) ;
518
516
return [
519
- `<div id="wormhole-connect" config='${ realConfigString } ' /></div>
517
+ `<div id="wormhole-connect" data- config='${ realConfigString } ' data-theme=' ${ customTheme } ' /></div>
520
518
<script type="module" src="https://www.unpkg.com/@wormhole-foundation/wormhole-connect@${ versionOrTag } /dist/main.js"${
521
519
versionOrTag === version
522
520
? ` integrity="${ versionScriptIntegrity } " crossorigin="anonymous"`
@@ -527,10 +525,10 @@ function App() {
527
525
? ` integrity="${ versionLinkIntegrity } " crossorigin="anonymous"`
528
526
: ""
529
527
} />`,
530
- `import WormholeBridge from '@wormhole-foundation/wormhole-connect';
528
+ `import WormholeConnect from '@wormhole-foundation/wormhole-connect';
531
529
function App() {
532
530
return (
533
- <WormholeBridge config={${ realConfigString } } ${
531
+ <WormholeConnect config={${ realConfigString } } ${
534
532
versionOrTag === version ? "" : ` versionOrTag="${ versionOrTag } "`
535
533
} />
536
534
);
@@ -706,7 +704,7 @@ function App() {
706
704
Widget
707
705
</ Typography >
708
706
< ColorPicker
709
- customTheme = { _customTheme }
707
+ customTheme = { customTheme }
710
708
setCustomTheme = { setCustomTheme }
711
709
path = "background.default"
712
710
defaultTheme = { customized }
@@ -720,7 +718,7 @@ function App() {
720
718
Modal
721
719
</ Typography >
722
720
< ColorPicker
723
- customTheme = { _customTheme }
721
+ customTheme = { customTheme }
724
722
setCustomTheme = { setCustomTheme }
725
723
path = "modal.background"
726
724
defaultTheme = { customized }
@@ -734,7 +732,7 @@ function App() {
734
732
Card
735
733
</ Typography >
736
734
< ColorPicker
737
- customTheme = { _customTheme }
735
+ customTheme = { customTheme }
738
736
setCustomTheme = { setCustomTheme }
739
737
path = "card.background"
740
738
defaultTheme = { customized }
@@ -748,7 +746,7 @@ function App() {
748
746
Button
749
747
</ Typography >
750
748
< ColorPicker
751
- customTheme = { _customTheme }
749
+ customTheme = { customTheme }
752
750
setCustomTheme = { setCustomTheme }
753
751
path = "button.primary"
754
752
defaultTheme = { customized }
@@ -762,7 +760,7 @@ function App() {
762
760
Action
763
761
</ Typography >
764
762
< ColorPicker
765
- customTheme = { _customTheme }
763
+ customTheme = { customTheme }
766
764
setCustomTheme = { setCustomTheme }
767
765
path = "button.action"
768
766
defaultTheme = { customized }
@@ -779,7 +777,7 @@ function App() {
779
777
Primary
780
778
</ Typography >
781
779
< ColorPicker
782
- customTheme = { _customTheme }
780
+ customTheme = { customTheme }
783
781
setCustomTheme = { setCustomTheme }
784
782
path = "text.primary"
785
783
defaultTheme = { customized }
@@ -793,7 +791,7 @@ function App() {
793
791
Secondary
794
792
</ Typography >
795
793
< ColorPicker
796
- customTheme = { _customTheme }
794
+ customTheme = { customTheme }
797
795
setCustomTheme = { setCustomTheme }
798
796
path = "text.secondary"
799
797
defaultTheme = { customized }
@@ -805,7 +803,7 @@ function App() {
805
803
Button
806
804
</Typography>
807
805
<ColorPicker
808
- customTheme={_customTheme }
806
+ customTheme={customTheme }
809
807
setCustomTheme={setCustomTheme}
810
808
path="button.primaryText"
811
809
/>
@@ -818,7 +816,7 @@ function App() {
818
816
Action
819
817
</ Typography >
820
818
< ColorPicker
821
- customTheme = { _customTheme }
819
+ customTheme = { customTheme }
822
820
setCustomTheme = { setCustomTheme }
823
821
path = "button.actionText"
824
822
defaultTheme = { customized }
@@ -840,7 +838,7 @@ function App() {
840
838
label = "Primary"
841
839
name = "primary"
842
840
fullWidth
843
- value = { getObjectPath ( _customTheme , "font.primary" ) }
841
+ value = { getObjectPath ( customTheme , "font.primary" ) }
844
842
onChange = { handleFontChange }
845
843
size = "small"
846
844
sx = { { mt : 2 } }
@@ -849,7 +847,7 @@ function App() {
849
847
label = "Header"
850
848
name = "header"
851
849
fullWidth
852
- value = { getObjectPath ( _customTheme , "font.header" ) }
850
+ value = { getObjectPath ( customTheme , "font.header" ) }
853
851
onChange = { handleFontChange }
854
852
size = "small"
855
853
sx = { { mt : 2 } }
@@ -985,8 +983,8 @@ function App() {
985
983
? "Unknown RPC string scheme. Expected an http or websocket URI."
986
984
: `Default: ${
987
985
( env === "mainnet"
988
- ? DEFAULT_MAINNET_RPCS [ n [ env ] ]
989
- : DEFAULT_TESTNET_RPCS [ n [ env ] ] ) || "None"
986
+ ? CONFIG . MAINNET . rpcs [ n [ env ] ]
987
+ : CONFIG . TESTNET . rpcs [ n [ env ] ] ) || "None"
990
988
} `
991
989
}
992
990
/>
@@ -1438,7 +1436,11 @@ function App() {
1438
1436
< Typography variant = "h4" component = "h2" gutterBottom >
1439
1437
Preview
1440
1438
</ Typography >
1441
- < WormholeBridge config = { config } key = { JSON . stringify ( config ) } />
1439
+ < WormholeConnect
1440
+ config = { config }
1441
+ theme = { customTheme }
1442
+ key = { JSON . stringify ( config ) }
1443
+ />
1442
1444
</ Container >
1443
1445
</ Box >
1444
1446
</ Background >
0 commit comments