Use query parameters to pass token address

This commit is contained in:
Franck 2021-12-22 15:22:37 +11:00
parent b081895cb2
commit 2bf0d0dcd1
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4

View File

@ -8,8 +8,11 @@ import pollingIcon from './assets/images/pollingIcon.png'
import { JsonRpcSigner } from '@ethersproject/providers' import { JsonRpcSigner } from '@ethersproject/providers'
import { orangeTheme } from '@dappconnect/vote-poll-sdk-react-components/dist/esm/src/style/themes' import { orangeTheme } from '@dappconnect/vote-poll-sdk-react-components/dist/esm/src/style/themes'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import { BrowserRouter, useParams } from 'react-router-dom' import { BrowserRouter } from 'react-router-dom'
import { Route, Switch } from 'react-router' import { Route, Switch } from 'react-router'
import { useLocation } from 'react-router-dom'
const sntTokenAddress = '0x744d70FDBE2Ba4CF95131626614a1763DF805B9E'
const config = { const config = {
readOnlyChainId: ChainId.Mainnet, readOnlyChainId: ChainId.Mainnet,
@ -41,7 +44,7 @@ export function Polling({ tokenAddress }: { tokenAddress: string }) {
<TopBar <TopBar
logo={pollingIcon} logo={pollingIcon}
logoWidth={84} logoWidth={84}
title={'Polling Dapp for DAI holders'} title={'WakuConnect Poll Demo'}
theme={orangeTheme} theme={orangeTheme}
activate={activateBrowserWallet} activate={activateBrowserWallet}
account={account} account={account}
@ -53,13 +56,14 @@ export function Polling({ tokenAddress }: { tokenAddress: string }) {
} }
export function PollingPage() { export function PollingPage() {
const { tokenAddress } = useParams<{ tokenAddress: string }>() const location = useLocation()
const tokenAddress = new URLSearchParams(location.search).get('token')
return ( return (
<Page> <Page>
<GlobalStyle /> <GlobalStyle />
<DAppProvider config={config}> <DAppProvider config={config}>
<Polling tokenAddress={tokenAddress} /> <Polling tokenAddress={tokenAddress ?? sntTokenAddress} />
</DAppProvider> </DAppProvider>
</Page> </Page>
) )
@ -79,7 +83,7 @@ ReactDOM.render(
<div style={{ height: '100%' }}> <div style={{ height: '100%' }}>
<BrowserRouter> <BrowserRouter>
<Switch> <Switch>
<Route exact path="/:tokenAddress" component={PollingPage} /> <Route exact path="/" component={PollingPage} />
</Switch> </Switch>
</BrowserRouter> </BrowserRouter>
</div>, </div>,