127127 </div >
128128 </div >
129129 </div >
130- <hr />
131130
132131 <!-- UI MODE YOUR OWN MODAL -->
133132 <div v-if =" form.selectedUiMode == 'customUi'" >
194193 :adapterConfig =" config.uiMode.default"
195194 :chain =" config.chain"
196195 v-if =" config.selectedUiMode === 'default' && config.authMode === 'hosted'"
197- ></ ConfigurableExample >
196+ / >
198197
199198 <WhitelabelExample
200199 :uiConfig =" config.uiMode.whitelabel"
201200 :chain =" config.chain"
202201 v-else-if =" config.selectedUiMode === 'whitelabel' && config.authMode === 'hosted'"
203- ></ WhitelabelExample >
202+ / >
204203
205204 <!-- Custom auth -->
206205 <CustomUiContainer :authType =" config.uiMode.customUi.type" v-if =" config.authMode === 'ownAuth'" ></CustomUiContainer >
213212import { LOGIN_PROVIDER } from " @toruslabs/openlogin" ;
214213import { CHAIN_NAMESPACES , ChainNamespaceType , EVM_ADAPTERS } from " @web3auth/base" ;
215214import { defaultEvmDappModalConfig , defaultSolanaDappModalConfig } from " @web3auth/web3auth" ;
215+ import { cloneDeep } from " lodash" ;
216216import merge from " lodash.merge" ;
217217import Vue from " vue" ;
218218
@@ -289,56 +289,59 @@ const defaultFormConfig = {
289289 },
290290};
291291
292- const defaultComponentConfig = {
293- chain: " ethereum" ,
294- authMode: " hosted" ,
295- selectedUiMode: " default" ,
296- openloginNetwork: " testnet" ,
297- plugins: {
298- torusWallet: true ,
299- },
300- uiMode: {
301- default: {
302- login: [... defaultLoginProviders ()],
303- adapter: defaultAdapters (CHAIN_NAMESPACES .EIP155 ),
304- },
305- customUi: {
306- type: " openlogin" ,
307- },
308- whitelabel: {
309- logoUrl: " https://cryptologos.cc/logos/solana-sol-logo.svg" ,
310- theme: " light" ,
311- loginMethodsOrder: DEFAULT_LOGIN_PROVIDERS ,
312- },
313- },
292+ const configFromSessionStorage = () => {
293+ const storedConfig = JSON .parse (sessionStorage .getItem (" web3AuthExampleConfig" )) ?? {};
294+ return storedConfig ;
295+ };
296+
297+ const configFromURL = () => {
298+ const params = new URLSearchParams (document .location .search );
299+ const chainParams = params .get (" chain" );
300+ const authModeParams = params .get (" auth" );
301+ const whitelabelParams = params .get (" whitelabel" );
302+
303+ // prettier-ignore
304+ return {
305+ ... ([" ethereum" , " solana" , " binance" , " polygon" ].includes (chainParams ) && { chain: chainParams }),
306+ ... (authModeParams === " custom" && { authMode: " ownAuth" }),
307+ ... (whitelabelParams === " yes" && { selectedUiMode: " whitelabel" }),
308+ };
314309};
310+
311+ const initialFormConfig = {
312+ ... defaultFormConfig ,
313+ ... configFromSessionStorage (),
314+ ... configFromURL (),
315+ };
316+
315317export default Vue .extend ({
316318 name: " home" ,
317319 data() {
318320 return {
319321 // storing config collected from user input.
320- form: { ... defaultFormConfig },
322+ form: { ... initialFormConfig },
321323 // sending to other components
322- config: { ... defaultComponentConfig },
323- tempLoginMethodsOrder: " " ,
324+ config: { ... cloneDeep ( initialFormConfig ) },
325+ tempLoginMethodsOrder: initialFormConfig . uiMode ?. whitelabel . loginMethodsOrder . join ( " , " ) ?? " " ,
324326 };
325327 },
326328 components: {
327329 ConfigurableExample: ConfigurableExample ,
328330 WhitelabelExample: WhitelabelExample ,
329331 CustomUiContainer ,
330332 },
331- mounted() {
332- const storedConfig = sessionStorage .getItem (" web3AuthExampleConfig" );
333- const finalStoredConfig = JSON .parse (storedConfig || " {}" );
334- this .config = merge (this .config , finalStoredConfig );
335- if (finalStoredConfig .uiMode ) this .config .uiMode .whitelabel .loginMethodsOrder = finalStoredConfig .uiMode .whitelabel .loginMethodsOrder ;
336- this .form = merge ({}, this .config );
337- // this.config.uiMode.default.login.push({
338- // id: "facebook",
339- // name: "Facebook",
340- // checked: false,
341- // });
333+ watch: {
334+ " form.authMode" (val ) {
335+ const formValURLSearchParamMap = { ownAuth: " custom" , hosted: " default" };
336+ this .updateURL (" auth" , formValURLSearchParamMap [val ]);
337+ },
338+ " form.chain" (val ) {
339+ this .updateURL (" chain" , val );
340+ },
341+ " form.selectedUiMode" (val ) {
342+ const formValURLSearchParamMap = { whitelabel: " yes" , default: " no" };
343+ this .updateURL (" whitelabel" , formValURLSearchParamMap [val ]);
344+ },
342345 },
343346 methods: {
344347 saveConfig : function () {
@@ -361,6 +364,11 @@ export default Vue.extend({
361364 setDefaultLoginMethodsOrder : function () {
362365 this .tempLoginMethodsOrder = DEFAULT_LOGIN_PROVIDERS .join (" ," );
363366 },
367+ updateURL(searchParamKey , searchParamValue ) {
368+ const url = new URL (window .location .href );
369+ url .searchParams .set (searchParamKey , searchParamValue );
370+ window .history .replaceState (null , null , url .toString ());
371+ },
364372 },
365373});
366374 </script >
@@ -389,6 +397,7 @@ body {
389397 border-right : 1px solid #ebecf0 ;
390398 background-color : #f4f5f7 ;
391399 padding : 20px ;
400+ padding-bottom : 60px ;
392401}
393402
394403.content {
0 commit comments