* chore: removes web3wallet example * refactor: updates sign-client to web3wallet * feat: implements auth * fix: resolves bug preventing approving only optional namespaces * feat: implements new design * UX flow for approving session proposals * feat: implements new designs in all modals * refactor: removes unused imports & groups imports into remote & local * feat: implements `isScam` alert on main request modal * feat: implements `threat prompt` * feat: updates all modals to new designs * chore: retrigger deployment --------- Co-authored-by: Gancho Radkov <ganchoradkov@gmail.com>
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { Divider, Text } from '@nextui-org/react'
|
|
import { Fragment } from 'react'
|
|
|
|
import ModalFooter from '@/components/ModalFooter'
|
|
import ProjectInfoCard from '@/components/ProjectInfoCard'
|
|
import RequestDataCard from '@/components/RequestDataCard'
|
|
import RequesDetailsCard from '@/components/RequestDetalilsCard'
|
|
import RequestMethodCard from '@/components/RequestMethodCard'
|
|
import RequestModalContainer from '@/components/RequestModalContainer'
|
|
import VerifyInfobox from '@/components/VerifyInfobox'
|
|
import ModalStore from '@/store/ModalStore'
|
|
import { styledToast } from '@/utils/HelperUtil'
|
|
import { approveTronRequest, rejectTronRequest } from '@/utils/TronRequestHandlerUtil'
|
|
import { web3wallet } from '@/utils/WalletConnectUtil'
|
|
import RequestModal from './RequestModal'
|
|
|
|
export default function SessionSignTronModal() {
|
|
// Get request and wallet data from store
|
|
const requestEvent = ModalStore.state.data?.requestEvent
|
|
const requestSession = ModalStore.state.data?.requestSession
|
|
|
|
// Ensure request and wallet are defined
|
|
if (!requestEvent || !requestSession) {
|
|
return <Text>Missing request data</Text>
|
|
}
|
|
|
|
// Get required request data
|
|
const { topic, params } = requestEvent
|
|
const { request, chainId } = params
|
|
|
|
// Handle approve action (logic varies based on request method)
|
|
async function onApprove() {
|
|
if (requestEvent) {
|
|
const response = await approveTronRequest(requestEvent)
|
|
try {
|
|
await web3wallet.respondSessionRequest({
|
|
topic,
|
|
response
|
|
})
|
|
} catch (e) {
|
|
styledToast((e as Error).message, 'error')
|
|
return
|
|
}
|
|
ModalStore.close()
|
|
}
|
|
}
|
|
|
|
// Handle reject action
|
|
async function onReject() {
|
|
if (requestEvent) {
|
|
const response = rejectTronRequest(requestEvent)
|
|
try {
|
|
await web3wallet.respondSessionRequest({
|
|
topic,
|
|
response
|
|
})
|
|
} catch (e) {
|
|
styledToast((e as Error).message, 'error')
|
|
return
|
|
}
|
|
ModalStore.close()
|
|
}
|
|
}
|
|
|
|
return (
|
|
<RequestModal
|
|
intention="sign a Tron message"
|
|
metadata={requestSession.peer.metadata}
|
|
onApprove={onApprove}
|
|
onReject={onReject}
|
|
>
|
|
<RequesDetailsCard chains={[chainId ?? '']} protocol={requestSession.relay.protocol} />
|
|
<Divider y={1} />
|
|
<RequestDataCard data={params} />
|
|
<Divider y={1} />
|
|
<RequestMethodCard methods={[request.method]} />
|
|
</RequestModal>
|
|
)
|
|
}
|