generated from Zoltu/preact-es2020-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* improve error handling * convert provider to signal * error handlers * remove unreachable condition * rename from account to session in contexts * Update app/ts/components/TokenPicker.tsx Co-authored-by: KillariDev <[email protected]> * Update app/ts/context/Notification.tsx Co-authored-by: KillariDev <[email protected]> * Update app/ts/library/errors.ts Co-authored-by: KillariDev <[email protected]> * token amount render --------- Co-authored-by: KillariDev <[email protected]>
- Loading branch information
1 parent
9395a69
commit 6c98987
Showing
36 changed files
with
816 additions
and
744 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useSignalEffect } from '@preact/signals' | ||
import { useEffect } from 'preact/hooks' | ||
import { useWallet } from '../context/Wallet.js' | ||
import { useEthereumProvider } from '../context/Ethereum.js' | ||
import { useAsyncState } from '../library/preact-utilities.js' | ||
import { EthereumAddress } from '../schema.js' | ||
|
||
export const AccountReconnect = () => { | ||
const { browserProvider } = useEthereumProvider() | ||
const { account } = useWallet() | ||
const { value: query, waitFor } = useAsyncState<EthereumAddress>() | ||
|
||
const attemptToConnect = () => { | ||
if (!browserProvider.value) return | ||
const provider = browserProvider.value | ||
waitFor(async () => { | ||
const [signer] = await provider.listAccounts() | ||
return EthereumAddress.parse(signer.address) | ||
}) | ||
} | ||
|
||
const listenForQueryChanges = () => { | ||
// do not reset shared state for other instances of this hooks | ||
if (query.value.state === 'inactive') return | ||
account.value = query.value | ||
} | ||
|
||
useSignalEffect(listenForQueryChanges) | ||
useEffect(attemptToConnect, []) | ||
|
||
return <></> | ||
} |
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 |
---|---|---|
@@ -1,29 +1,28 @@ | ||
import { Route, Router } from './HashRouter.js' | ||
import { Notices } from './Notice.js' | ||
import { SplashScreen } from './SplashScreen.js' | ||
import { TransactionPage } from './TransactionPage/index.js' | ||
import { ErrorAlert } from './ErrorAlert.js' | ||
import { TransferPage } from './TransferPage/index.js' | ||
import { EthereumProvider } from '../context/Ethereum.js' | ||
import { WalletProvider } from '../context/Wallet.js' | ||
import { AccountProvider } from '../context/Account.js' | ||
import { NotificationProvider } from '../context/Notification.js' | ||
|
||
export function App() { | ||
return ( | ||
<SplashScreen> | ||
<WalletProvider> | ||
<AccountProvider> | ||
<Router> | ||
<Route path=''> | ||
<TransferPage /> | ||
</Route> | ||
<Route path='#tx/:transaction_hash'> | ||
<TransactionPage /> | ||
</Route> | ||
</Router> | ||
<Notices /> | ||
<ErrorAlert /> | ||
</AccountProvider> | ||
</WalletProvider> | ||
<NotificationProvider> | ||
<EthereumProvider> | ||
<WalletProvider> | ||
<Router> | ||
<Route path=''> | ||
<TransferPage /> | ||
</Route> | ||
<Route path='#tx/:transaction_hash'> | ||
<TransactionPage /> | ||
</Route> | ||
</Router> | ||
</WalletProvider> | ||
</EthereumProvider> | ||
</NotificationProvider> | ||
</SplashScreen> | ||
) | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.