1
0
Fork 0
This commit is contained in:
Matthias Kretschmann 2024-03-13 10:37:05 +00:00
parent feee0c678b
commit 8c63ec0c47
Signed by: m
GPG Key ID: 606EEEF3C479A91F
5 changed files with 11 additions and 18 deletions

View File

@ -12,7 +12,7 @@ export function Preview() {
const { ens } = siteConfig.author.ether const { ens } = siteConfig.author.ether
const { data: to } = useEnsAddress({ name: ens, chainId: 1 }) const { data: to } = useEnsAddress({ name: ens, chainId: 1 })
const { data: ensResolved } = useEnsName({ const { data: ensResolved } = useEnsName({
address: to as `0x${string}` | undefined, address: to as `0x${string}`,
chainId: 1 chainId: 1
}) })

View File

@ -10,6 +10,7 @@
.actions { .actions {
display: flex; display: flex;
justify-content: center; justify-content: center;
margin-top: 2rem;
} }
.actions button { .actions button {
@ -17,7 +18,3 @@
height: 45px; height: 45px;
padding: 0; padding: 0;
} }
.success code {
font-size: var(--font-size-small);
}

View File

@ -1,5 +1,4 @@
import { $txHash, $isInitSend } from '@features/Web3/stores' import { $isInitSend } from '@features/Web3/stores'
import { useStore } from '@nanostores/react'
import styles from './Success.module.css' import styles from './Success.module.css'
import { useAccount } from 'wagmi' import { useAccount } from 'wagmi'
import { ExplorerLink } from './ExplorerLink' import { ExplorerLink } from './ExplorerLink'
@ -9,7 +8,6 @@ const description = `Your transaction is on its way. You can check the status on
export function Success() { export function Success() {
const account = useAccount() const account = useAccount()
const txHash = useStore($txHash)
const explorerName = account?.chain?.blockExplorers?.default.name const explorerName = account?.chain?.blockExplorers?.default.name
const explorerUrl = account?.chain?.blockExplorers?.default.url const explorerUrl = account?.chain?.blockExplorers?.default.url
@ -22,18 +20,13 @@ export function Success() {
{description}{' '} {description}{' '}
<ExplorerLink url={explorerUrl}>{explorerName}</ExplorerLink>. <ExplorerLink url={explorerUrl}>{explorerName}</ExplorerLink>.
</p> </p>
<p>
<ExplorerLink url={explorerUrl}>
<code>{txHash}</code>
</ExplorerLink>
</p>
<footer className={styles.actions}> <footer className={styles.actions}>
<button <button
onClick={() => $isInitSend.set(false)} onClick={() => $isInitSend.set(false)}
className="btn btn-primary" className="btn btn-primary"
> >
Reset Close
</button> </button>
</footer> </footer>
</div> </div>

View File

@ -8,7 +8,7 @@ export async function send(
config: UseConfigReturnType, config: UseConfigReturnType,
selectedToken: GetToken | undefined, selectedToken: GetToken | undefined,
amount: string | undefined, amount: string | undefined,
to: `0x${string}` | undefined, to: `0x${string}` | null | undefined,
chainId: number | undefined chainId: number | undefined
) { ) {
if (!selectedToken?.decimals || !amount || !to) return if (!selectedToken?.decimals || !amount || !to) return

View File

@ -3,13 +3,16 @@ import { useStore } from '@nanostores/react'
import { useState } from 'react' import { useState } from 'react'
import { send } from './send' import { send } from './send'
import { isUnhelpfulErrorMessage } from './isUnhelpfulErrorMessage' import { isUnhelpfulErrorMessage } from './isUnhelpfulErrorMessage'
import { useAccount, useConfig } from 'wagmi' import { useAccount, useConfig, useEnsAddress } from 'wagmi'
import siteConfig from '@config/blog.config'
export function useSend() { export function useSend() {
const selectedToken = useStore($selectedToken) const selectedToken = useStore($selectedToken)
const amount = useStore($amount) const amount = useStore($amount)
const config = useConfig() const config = useConfig()
const { address, chainId } = useAccount() const { chainId } = useAccount()
const { ens } = siteConfig.author.ether
const { data: to } = useEnsAddress({ name: ens, chainId: 1 })
const [isLoading, setIsLoading] = useState(false) const [isLoading, setIsLoading] = useState(false)
const [isError, setIsError] = useState(false) const [isError, setIsError] = useState(false)
@ -20,7 +23,7 @@ export function useSend() {
setIsError(false) setIsError(false)
setError(undefined) setError(undefined)
setIsLoading(true) setIsLoading(true)
const hash = await send(config, selectedToken, amount, address, chainId) const hash = await send(config, selectedToken, amount, to, chainId)
if (hash) $txHash.set(hash) if (hash) $txHash.set(hash)
} catch (error: unknown) { } catch (error: unknown) {
const errorMessage = (error as Error).message const errorMessage = (error as Error).message