Skip to content

Commit

Permalink
Merge pull request #2720 from CityOfZion/CU-86dt27e2r
Browse files Browse the repository at this point in the history
CU-86dt27e2r - NEON2 - Implement a WC request to wipe all requests fr…
  • Loading branch information
melanke authored Apr 26, 2024
2 parents 0e68a00 + 5fb8871 commit 43ec7bd
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 150 deletions.
12 changes: 6 additions & 6 deletions app/components/DappRequest/Decrypt/Decrypt.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import WarningIcon from '../../../assets/icons/warning.svg'
import Confirm from '../../../assets/icons/confirm_connection.svg'
import Deny from '../../../assets/icons/deny_connection.svg'
import ConnectionLoader from '../../ConnectDapp/ConnectionLoader'
import MessageSuccess from '../MessageSuccess'

type Props = {
request: TSessionRequest,
Expand All @@ -40,7 +39,6 @@ const Decrypt = ({
const { approveRequest, rejectRequest } = useWalletConnectWallet()

const [loading, setLoading] = useState(false)
const [success, setSuccess] = useState(false)

const reject = () => {
rejectRequest(request)
Expand All @@ -54,7 +52,11 @@ const Decrypt = ({
try {
setLoading(true)
await approveRequest(request)
setSuccess(true)

history.push({
pathname: ROUTES.DAPP_REQUEST_RESULT,
state: { content: 'You have successfully decrypted your message' },
})
} catch (error) {
showErrorNotification({ message: error.message })
history.push(ROUTES.DASHBOARD)
Expand All @@ -65,9 +67,7 @@ const Decrypt = ({

if (loading) return <ConnectionLoader />

return success ? (
<MessageSuccess text="You have successfully decrypted your message" />
) : (
return (
<FullHeightPanel
headerText="Wallet Connect"
renderCloseButton={() => (
Expand Down
12 changes: 6 additions & 6 deletions app/components/DappRequest/DecryptFromArray/DecryptFromArray.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import WarningIcon from '../../../assets/icons/warning.svg'
import Confirm from '../../../assets/icons/confirm_connection.svg'
import Deny from '../../../assets/icons/deny_connection.svg'
import ConnectionLoader from '../../ConnectDapp/ConnectionLoader'
import MessageSuccess from '../MessageSuccess'

type Props = {
request: TSessionRequest,
Expand All @@ -40,7 +39,6 @@ const DecryptFromArray = ({
const { approveRequest, rejectRequest } = useWalletConnectWallet()

const [loading, setLoading] = useState(false)
const [success, setSuccess] = useState(false)

const reject = () => {
rejectRequest(request)
Expand All @@ -54,7 +52,11 @@ const DecryptFromArray = ({
try {
setLoading(true)
await approveRequest(request)
setSuccess(true)

history.push({
pathname: ROUTES.DAPP_REQUEST_RESULT,
state: { content: 'You have successfully decrypted your messages' },
})
} catch (error) {
showErrorNotification({ message: error.message })
history.push(ROUTES.DASHBOARD)
Expand All @@ -65,9 +67,7 @@ const DecryptFromArray = ({

if (loading) return <ConnectionLoader />

return success ? (
<MessageSuccess text="You have successfully decrypted your messages" />
) : (
return (
<FullHeightPanel
headerText="Wallet Connect"
renderCloseButton={() => (
Expand Down
12 changes: 6 additions & 6 deletions app/components/DappRequest/Encrypt/Encrypt.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import WarningIcon from '../../../assets/icons/warning.svg'
import Confirm from '../../../assets/icons/confirm_connection.svg'
import Deny from '../../../assets/icons/deny_connection.svg'
import ConnectionLoader from '../../ConnectDapp/ConnectionLoader'
import MessageSuccess from '../MessageSuccess'

type Props = {
request: TSessionRequest,
Expand All @@ -39,7 +38,6 @@ const Encrypt = ({
const { approveRequest, rejectRequest } = useWalletConnectWallet()

const [loading, setLoading] = useState(false)
const [success, setSuccess] = useState(false)

const reject = () => {
rejectRequest(request)
Expand All @@ -53,7 +51,11 @@ const Encrypt = ({
try {
setLoading(true)
await approveRequest(request)
setSuccess(true)

history.push({
pathname: ROUTES.DAPP_REQUEST_RESULT,
state: { content: 'You have successfully encrypted your message' },
})
} catch (error) {
showErrorNotification({ message: error.message })
history.push(ROUTES.DASHBOARD)
Expand All @@ -64,9 +66,7 @@ const Encrypt = ({

if (loading) return <ConnectionLoader />

return success ? (
<MessageSuccess text="You have successfully encrypted your message" />
) : (
return (
<FullHeightPanel
headerText="Wallet Connect"
renderCloseButton={() => (
Expand Down
21 changes: 12 additions & 9 deletions app/components/DappRequest/InvokeFunction/InvokeFunction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ const InvokeFunction = ({
const { rejectRequest, approveRequest } = useWalletConnectWallet()
const [loading, setLoading] = useState(false)
const [fee, setFee] = useState()
const [transactionHash, setTransactionHash] = useState()
const [errorMessage, setErrorMessage] = useState()

const witnessScope = useMemo(
() => {
Expand Down Expand Up @@ -136,9 +134,19 @@ const InvokeFunction = ({
hideNotification(notificationId)
}

setTransactionHash(result)
history.push({
pathname: ROUTES.DAPP_REQUEST_RESULT,
state: {
content: <InvokeResult transactionHash={result} />,
},
})
} catch (error) {
setErrorMessage(error.message)
history.push({
pathname: ROUTES.DAPP_REQUEST_RESULT,
state: {
content: <InvokeResult errorMessage={error.message} />,
},
})
} finally {
setLoading(false)
}
Expand All @@ -153,11 +161,6 @@ const InvokeFunction = ({

return loading ? (
<ConnectionLoader />
) : transactionHash || errorMessage ? (
<InvokeResult
transactionHash={transactionHash}
errorMessage={errorMessage}
/>
) : (
<FullHeightPanel
headerText="Wallet Connect"
Expand Down
71 changes: 28 additions & 43 deletions app/components/DappRequest/InvokeFunction/InvokeResult.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
/* eslint-disable no-nested-ternary */
// @flow
import React from 'react'
import { ROUTES } from '../../../core/constants'
import CloseButton from '../../CloseButton'
import FullHeightPanel from '../../Panel/FullHeightPanel'
import WallletConnect from '../../../assets/icons/wallet_connect.svg'
import styles from '../../../containers/ConnectDapp/styles.scss'
import CheckMarkIcon from '../../../assets/icons/confirm-circle.svg'
import ErrorIcon from '../../../assets/icons/wc-error.svg'
Expand All @@ -15,46 +11,35 @@ type Props = {
}

const InvokeResult = ({ transactionHash, errorMessage }: Props) => (
<FullHeightPanel
headerText="Wallet Connect"
renderCloseButton={() => <CloseButton routeTo={ROUTES.DASHBOARD} />}
renderHeaderIcon={() => (
<div>
<WallletConnect />
</div>
)}
renderInstructions={false}
>
<div className={styles.txSuccessContainer}>
{transactionHash ? (
<>
<CheckMarkIcon />
<h3> Transaction pending!</h3>
<p>
Once your transaction has been confirmed it will appear in your
activity feed.
</p>
<br />
<br />
<p>
<label>TRANSACTION ID</label>
<br />
<code>{transactionHash}</code>
</p>
</>
) : errorMessage ? (
<>
<ErrorIcon />
<h3>Transaction failed!</h3>
<p>{errorMessage}</p>
<div className={styles.txSuccessContainer}>
{transactionHash ? (
<>
<CheckMarkIcon />
<h3> Transaction pending!</h3>
<p>
Once your transaction has been confirmed it will appear in your
activity feed.
</p>
<br />
<br />
<p>
<label>TRANSACTION ID</label>
<br />
<br />
</>
) : (
<></>
)}
</div>
</FullHeightPanel>
<code>{transactionHash}</code>
</p>
</>
) : errorMessage ? (
<>
<ErrorIcon />
<h3>Transaction failed!</h3>
<p>{errorMessage}</p>
<br />
<br />
</>
) : (
<></>
)}
</div>
)

export default InvokeResult
34 changes: 0 additions & 34 deletions app/components/DappRequest/MessageSuccess.jsx

This file was deleted.

12 changes: 6 additions & 6 deletions app/components/DappRequest/SignMessage/SignMessage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import WarningIcon from '../../../assets/icons/warning.svg'
import Confirm from '../../../assets/icons/confirm_connection.svg'
import Deny from '../../../assets/icons/deny_connection.svg'
import ConnectionLoader from '../../ConnectDapp/ConnectionLoader'
import MessageSuccess from '../MessageSuccess'

type Props = {
request: TSessionRequest,
Expand All @@ -39,7 +38,6 @@ const VerifyMessage = ({
const { approveRequest, rejectRequest } = useWalletConnectWallet()

const [loading, setLoading] = useState(false)
const [success, setSuccess] = useState(false)

const reject = () => {
rejectRequest(request)
Expand All @@ -53,7 +51,11 @@ const VerifyMessage = ({
try {
setLoading(true)
await approveRequest(request)
setSuccess(true)

history.push({
pathname: ROUTES.DAPP_REQUEST_RESULT,
state: { content: 'You have successfully signed your message' },
})
} catch (error) {
showErrorNotification({ message: error.message })
history.push(ROUTES.DASHBOARD)
Expand All @@ -64,9 +66,7 @@ const VerifyMessage = ({

if (loading) return <ConnectionLoader />

return success ? (
<MessageSuccess text="You have successfully signed your message" />
) : (
return (
<FullHeightPanel
headerText="Wallet Connect"
renderCloseButton={() => (
Expand Down
11 changes: 5 additions & 6 deletions app/components/DappRequest/SignTransaction/SignTransaction.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import Info from '../../../assets/icons/info.svg'

import { getNode, getRPCEndpoint } from '../../../actions/nodeStorageActions'
import Invocation from '../components/Invocation'
import MessageSuccess from '../MessageSuccess'

const electron = require('electron')

Expand Down Expand Up @@ -59,7 +58,6 @@ const SignTransaction = ({
const { rejectRequest, approveRequest } = useWalletConnectWallet()
const [loading, setLoading] = useState(false)
const [fee, setFee] = useState()
const [success, setSuccess] = useState(false)

const handleCalculateFee = useCallback(
async () => {
Expand Down Expand Up @@ -121,7 +119,10 @@ const SignTransaction = ({
hideNotification(notificationId)
}

setSuccess(true)
history.push({
pathname: ROUTES.DAPP_REQUEST_RESULT,
state: { content: 'You have successfully signed your transaction' },
})
} finally {
setLoading(false)
}
Expand All @@ -134,10 +135,8 @@ const SignTransaction = ({
[handleCalculateFee],
)

return loading && !success ? (
return loading ? (
<ConnectionLoader />
) : success ? (
<MessageSuccess text="You have successfully signed your transaction" />
) : (
<FullHeightPanel
headerText="Wallet Connect"
Expand Down
Loading

0 comments on commit 43ec7bd

Please sign in to comment.