fix(error-handling): close modal on reject and fix overflow error (#147)
* fix(error-handling): improve auth examples error handling & close modal on auth request rejection * fix(bignum-overflow): convert bignumber to string to avoid overflow
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Fragment, useCallback, useEffect, useState } from 'react'
|
||||
import RequestModalContainer from '@/components/RequestModalContainer'
|
||||
import ModalStore from '@/store/ModalStore'
|
||||
import { Button, Col, Divider, Modal, Row, Text } from '@nextui-org/react'
|
||||
import { Button, Col, Modal, Row, Text } from '@nextui-org/react'
|
||||
import { createOrRestoreEIP155Wallet } from '@/utils/EIP155WalletUtil'
|
||||
import { authClient } from '@/utils/WalletConnectUtil'
|
||||
|
||||
@@ -15,27 +15,30 @@ export default function AuthenticationRequestModal() {
|
||||
useEffect(() => {
|
||||
if (message) return
|
||||
const address = eip155Addresses[0]
|
||||
const iss = `did:pkh:${authenticationRequest.params.cacaoPayload.chainId}:${address}`
|
||||
setMessage(authClient.formatMessage(authenticationRequest.params.cacaoPayload, iss))
|
||||
const iss = `did:pkh:${params.cacaoPayload.chainId}:${address}`
|
||||
setMessage(authClient.formatMessage(params.cacaoPayload, iss))
|
||||
setIss(iss)
|
||||
}, [authenticationRequest.params.cacaoPayload, eip155Addresses, message])
|
||||
}, [params.cacaoPayload, eip155Addresses, message])
|
||||
|
||||
const onApprove = useCallback(async () => {
|
||||
if (authenticationRequest && iss && message) {
|
||||
console.log({ eip155Wallets })
|
||||
|
||||
const signature = await eip155Wallets[eip155Addresses[0]].signMessage(message)
|
||||
await authClient.respond(
|
||||
{
|
||||
id,
|
||||
signature: {
|
||||
s: signature,
|
||||
t: 'eip191'
|
||||
}
|
||||
},
|
||||
iss
|
||||
)
|
||||
ModalStore.close()
|
||||
try {
|
||||
const signature = await eip155Wallets[eip155Addresses[0]].signMessage(message)
|
||||
await authClient.respond(
|
||||
{
|
||||
id,
|
||||
signature: {
|
||||
s: signature,
|
||||
t: 'eip191'
|
||||
}
|
||||
},
|
||||
iss
|
||||
)
|
||||
} catch (onApproveError) {
|
||||
console.log({ onApproveError })
|
||||
} finally {
|
||||
ModalStore.close()
|
||||
}
|
||||
}
|
||||
}, [authenticationRequest, eip155Addresses, eip155Wallets, id, iss, message])
|
||||
|
||||
@@ -45,6 +48,22 @@ export default function AuthenticationRequestModal() {
|
||||
|
||||
// Handle reject action
|
||||
async function onReject() {
|
||||
if (id && iss) {
|
||||
try {
|
||||
await authClient.respond(
|
||||
{
|
||||
id,
|
||||
error: {
|
||||
code: 4001,
|
||||
message: 'Auth request has been rejected'
|
||||
}
|
||||
},
|
||||
iss
|
||||
)
|
||||
} catch (onRejectError) {
|
||||
console.log({ onRejectError })
|
||||
}
|
||||
}
|
||||
ModalStore.close()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user