mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
switching alert messages and reducing return statements
This commit is contained in:
parent
c657429eb1
commit
41a4f6497a
@ -13,33 +13,52 @@ export default function Permission({
|
|||||||
children: ReactElement
|
children: ReactElement
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const url = appConfig.rbacUrl
|
const url = appConfig.rbacUrl
|
||||||
const [data, updateData] = useState<boolean>()
|
const [data, updateData] = useState<boolean | 'ERROR'>()
|
||||||
|
const [errorMessage, updateError] = useState<string>()
|
||||||
|
const [messageState, updateMessageState] = useState<
|
||||||
|
'error' | 'warning' | 'info' | 'success'
|
||||||
|
>()
|
||||||
const { accountId } = useWeb3()
|
const { accountId } = useWeb3()
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (url === undefined) return
|
if (url === undefined) return
|
||||||
const getData = async () => {
|
const getData = async () => {
|
||||||
if (accountId !== undefined) {
|
if (accountId === undefined) {
|
||||||
|
console.log('accountId', accountId)
|
||||||
|
updateError('Please make sure your wallet is connected to proceed.')
|
||||||
|
updateMessageState('info')
|
||||||
|
} else {
|
||||||
const data = await rbacRequest(eventType, accountId)
|
const data = await rbacRequest(eventType, accountId)
|
||||||
updateData(data)
|
updateData(data)
|
||||||
|
if (data === 'ERROR') {
|
||||||
|
updateError(
|
||||||
|
'There was an error verifying your permissions. Please refresh the page or conntact your network administrator'
|
||||||
|
)
|
||||||
|
updateMessageState('error')
|
||||||
|
} else if (data === false) {
|
||||||
|
updateError(
|
||||||
|
`Sorry, you don't have permission to ${eventType}. Please make sure you have connected your registered address.`
|
||||||
|
)
|
||||||
|
updateMessageState('warning')
|
||||||
|
} else if (data !== true) {
|
||||||
|
updateError(
|
||||||
|
'An unkown error occured. Please conntact your network administrator'
|
||||||
|
)
|
||||||
|
updateMessageState('error')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getData()
|
getData()
|
||||||
}, [eventType, accountId, url])
|
}, [eventType, accountId, url])
|
||||||
|
|
||||||
if (url === undefined || data === true) {
|
if (url === undefined || data === true) {
|
||||||
return <>{children}</>
|
return <>{children}</>
|
||||||
} else if (data === false) {
|
|
||||||
const message = `Sorry, you don't have permission to ${eventType}. Please make sure you have connected your registered address.`
|
|
||||||
return <Alert title="Permission denied" text={message} state="error" />
|
|
||||||
} else {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Alert
|
|
||||||
text="Please make sure your wallet is connected to proceed."
|
|
||||||
state="info"
|
|
||||||
/>
|
|
||||||
<br />
|
|
||||||
<Loader />
|
|
||||||
</>
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Alert text={errorMessage} state={messageState} />
|
||||||
|
<br />
|
||||||
|
<Loader />
|
||||||
|
</>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import appConfig from '../../app.config'
|
|||||||
export default async function rbacRequest(
|
export default async function rbacRequest(
|
||||||
eventType: string,
|
eventType: string,
|
||||||
address: string
|
address: string
|
||||||
): Promise<boolean> {
|
): Promise<boolean | 'ERROR'> {
|
||||||
const url = appConfig.rbacUrl
|
const url = appConfig.rbacUrl
|
||||||
if (url === undefined) {
|
if (url === undefined) {
|
||||||
return true
|
return true
|
||||||
@ -28,6 +28,7 @@ export default async function rbacRequest(
|
|||||||
return await response.json()
|
return await response.json()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error parsing json: ' + error.message)
|
console.error('Error parsing json: ' + error.message)
|
||||||
|
return 'ERROR'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user