-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Hydrated and config nextjs router
- Loading branch information
1 parent
a01aade
commit 3076167
Showing
4 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use client'; | ||
|
||
import configs from '@/constants/l2ass.constant'; | ||
import { useContext, useEffect, useState } from 'react'; | ||
import { useRouter } from 'next/navigation'; | ||
|
||
export enum IframeEventName { | ||
topup = 'topup', | ||
create_gamefi_wallet = 'create_gamefi_wallet', | ||
import_gamefi_wallet = 'import_gamefi_wallet', | ||
hide_sidebar = 'hide_sidebar', | ||
open_sidebar = 'open_sidebar', | ||
trustless_computer_change_route = 'trustless-computer-change-route', | ||
} | ||
export interface IFrameEvent { | ||
data: { | ||
name: IframeEventName; | ||
}; | ||
} | ||
|
||
const Hydrated = ({ children }: { children?: any }) => { | ||
const [hydration, setHydration] = useState(false); | ||
const router = useRouter(); | ||
|
||
useEffect(() => { | ||
if (typeof window !== 'undefined') { | ||
setHydration(true); | ||
} | ||
}, []); | ||
|
||
useEffect(() => { | ||
if (hydration && window) { | ||
window.onmessage = function (event: IFrameEvent & any) { | ||
try { | ||
const eventData = JSON.parse(event.data); | ||
console.log; | ||
switch (eventData.name) { | ||
case IframeEventName.trustless_computer_change_route: { | ||
const subUrl = (eventData.url || '').split('/'); | ||
if (subUrl.length > 0) { | ||
let lastSubUrl: string = subUrl[subUrl.length - 1]; | ||
|
||
// lastSubUrl = lastSubUrl.replaceAll('buy', 'customize'); | ||
// if (lastSubUrl.includes('trustless-computers-iframe')) { | ||
// window.history.replaceState({}, '', '/blockchains'); | ||
// } else { | ||
// window.history.replaceState( | ||
// {}, | ||
// '', | ||
// '/blockchains/' + lastSubUrl, | ||
// ); | ||
// } | ||
|
||
if (lastSubUrl === 'buy') { | ||
router.replace('/blockchains/customize'); | ||
} else { | ||
} | ||
} | ||
break; | ||
} | ||
default: | ||
break; | ||
} | ||
} catch (error) {} | ||
}; | ||
} | ||
}, [hydration]); | ||
|
||
return hydration ? children : null; | ||
}; | ||
|
||
export default Hydrated; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// import { CDN_URL_IMAGES } from '@/configs'; | ||
|
||
import { isProduction } from '@/config'; | ||
|
||
const MAIN_PATH = '/trustless-computers-iframe/'; | ||
const APP_URL = | ||
(isProduction | ||
? 'https://newbitcoincity.com' | ||
: 'https://dev.newbitcoincity.com') + MAIN_PATH; | ||
|
||
const DASH_BOARD_URL = APP_URL + 'computers/'; | ||
const TOKEN_URL = APP_URL + 'token/'; | ||
const PRICE_URL = APP_URL + 'price/'; | ||
const BUY_URL = APP_URL + 'buy/'; | ||
|
||
// const META_DATA = { | ||
// title: 'Trustless Computer', | ||
// description: 'Launch your own Bitcoin L2 blockchain in one click.', | ||
// image: `${CDN_URL_IMAGES}/trustless-computer-metadata-01.png`, | ||
// }; | ||
|
||
const configs = { | ||
APP_URL, | ||
DASH_BOARD_URL, | ||
TOKEN_URL, | ||
PRICE_URL, | ||
// META_DATA, | ||
BUY_URL, | ||
MAIN_PATH, | ||
}; | ||
|
||
export default configs; |