mirror of
https://github.com/kremalicious/blog.git
synced 2024-11-22 09:56:51 +01:00
error handling before send
This commit is contained in:
parent
ad22b84349
commit
324d032326
@ -19,7 +19,10 @@ export function Web3Form(): ReactElement {
|
|||||||
const [error, setError] = useState<string>()
|
const [error, setError] = useState<string>()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!amount || amount === '' || !selectedToken?.balance) return
|
if (!amount || amount === '' || !selectedToken?.balance) {
|
||||||
|
setError(undefined)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (Number(amount) > Number(selectedToken?.balance)) {
|
if (Number(amount) > Number(selectedToken?.balance)) {
|
||||||
setError('Exceeds balance')
|
setError('Exceeds balance')
|
||||||
|
@ -103,13 +103,13 @@
|
|||||||
text-shadow: none;
|
text-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.error {
|
.errorOutput {
|
||||||
color: red;
|
color: red;
|
||||||
font-size: var(--font-size-small);
|
font-size: var(--font-size-mini);
|
||||||
margin-left: var(--tokenWidth);
|
margin-left: var(--tokenWidth);
|
||||||
text-align: left;
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 0;
|
right: calc(var(--spacer) / 3);
|
||||||
bottom: 0;
|
bottom: -3px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
text-align: right;
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ export function InputGroup({
|
|||||||
Preview
|
Preview
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
{error ? <span className={styles.error}>{error}</span> : null}
|
{error ? <span className={styles.errorOutput}>{error}</span> : null}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Conversion />
|
<Conversion />
|
||||||
|
@ -4,16 +4,18 @@
|
|||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
background: none;
|
background: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
code.to,
|
||||||
|
code.from {
|
||||||
font-size: var(--font-size-mini);
|
font-size: var(--font-size-mini);
|
||||||
}
|
}
|
||||||
|
|
||||||
.to:last-child:not(:only-child),
|
.to:last-child {
|
||||||
.from:last-child:not(:only-child) {
|
|
||||||
padding-left: 14px;
|
padding-left: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.to:last-child:not(:only-child)::first-letter,
|
.to:last-child::first-letter {
|
||||||
.from:last-child:not(:only-child)::first-letter {
|
|
||||||
margin-left: -14px;
|
margin-left: -14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,8 +44,7 @@ export function Data({
|
|||||||
<td className={styles.label}>You are</td>
|
<td className={styles.label}>You are</td>
|
||||||
{ensFrom ? (
|
{ensFrom ? (
|
||||||
<td title={`${ensFrom} successfully resolved to ${from}`}>
|
<td title={`${ensFrom} successfully resolved to ${from}`}>
|
||||||
<code className={styles.from}>{ensFrom}</code>
|
<span className={styles.from}>{ensFrom}</span>
|
||||||
<code className={styles.from}>{`→ ${from}`}</code>
|
|
||||||
</td>
|
</td>
|
||||||
) : (
|
) : (
|
||||||
<td>
|
<td>
|
||||||
@ -73,7 +72,7 @@ export function Data({
|
|||||||
<tr>
|
<tr>
|
||||||
<td className={styles.label}>to</td>
|
<td className={styles.label}>to</td>
|
||||||
<td title={`${ensResolved} successfully resolved to ${to}`}>
|
<td title={`${ensResolved} successfully resolved to ${to}`}>
|
||||||
<code className={styles.to}>{ensResolved}</code>
|
<span className={styles.to}>{ensResolved}</span>
|
||||||
<code className={styles.to}>{`→ ${to}`}</code>
|
<code className={styles.to}>{`→ ${to}`}</code>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -26,10 +26,21 @@ export function useSend({
|
|||||||
const result = await send(selectedToken, txConfig)
|
const result = await send(selectedToken, txConfig)
|
||||||
$txHash.set(result?.hash)
|
$txHash.set(result?.hash)
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
console.error((error as Error).message)
|
const errorMessage = (error as Error).message
|
||||||
|
console.error(errorMessage)
|
||||||
|
|
||||||
// only expose useful errors in UI
|
// only expose useful errors in UI
|
||||||
if ((error as Error).message.includes('User rejected the request.')) {
|
const terribleErrorMessages = [
|
||||||
|
'User rejected the request.',
|
||||||
|
'User denied transaction signature.',
|
||||||
|
'Cannot read properties of undefined'
|
||||||
|
]
|
||||||
|
|
||||||
|
if (
|
||||||
|
terribleErrorMessages.some((terribleMessage) =>
|
||||||
|
errorMessage.includes(terribleMessage)
|
||||||
|
)
|
||||||
|
) {
|
||||||
setError(undefined)
|
setError(undefined)
|
||||||
} else {
|
} else {
|
||||||
setError((error as Error).message)
|
setError((error as Error).message)
|
||||||
|
Loading…
Reference in New Issue
Block a user