improve alert modal buttons and fix alerts not loading on connect wallet (#8)

This commit is contained in:
saml33 2021-05-11 06:32:21 +10:00 committed by GitHub
parent 058abf8fa2
commit 8e4bd926a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 18 deletions

View File

@ -111,12 +111,22 @@ const AlertsModal: FunctionComponent<AlertsModalProps> = ({
copyToClipboard(code) copyToClipboard(code)
} }
const handleCloseTgCodeView = () => { const handleNewFromTgCode = () => {
set((s) => {
s.tgCode = null
})
resetForm() resetForm()
setShowTgCode(false)
} }
const handleCloseSuccessView = () => { const handleCloseModal = () => {
set((s) => {
;(s.success = ''), (s.tgCode = null)
})
resetForm()
onClose()
}
const handleNewFromSuccess = () => {
resetForm() resetForm()
set((s) => { set((s) => {
s.success = '' s.success = ''
@ -169,13 +179,14 @@ const AlertsModal: FunctionComponent<AlertsModalProps> = ({
} }
return ( return (
<Modal isOpen={isOpen} onClose={onClose}> <Modal isOpen={isOpen} onClose={handleCloseModal}>
{tgCode && showTgCode ? ( {tgCode && showTgCode ? (
<TelegramModal <TelegramModal
tgCode={tgCode} handleCloseModal={handleCloseModal}
handleCopyToClipboard={handleCopyTgCode} handleCopyToClipboard={handleCopyTgCode}
handleCloseTgCodeView={handleCloseTgCodeView} handleNewFromTgCode={handleNewFromTgCode}
isCopied={isCopied} isCopied={isCopied}
tgCode={tgCode}
/> />
) : success ? ( ) : success ? (
<div className="flex flex-col items-center text-th-fgd-1"> <div className="flex flex-col items-center text-th-fgd-1">
@ -184,12 +195,17 @@ const AlertsModal: FunctionComponent<AlertsModalProps> = ({
<p className="text-center"> <p className="text-center">
{"We'll let you know if it's triggered."} {"We'll let you know if it's triggered."}
</p> </p>
<div className="flex pt-2 w-full">
<Button <Button
onClick={() => handleCloseSuccessView()} onClick={() => handleNewFromSuccess()}
className="w-full mt-2" className="w-full mr-2"
> >
Okay, Got It New Alert
</Button> </Button>
<Button onClick={() => handleCloseModal()} className="w-full ml-2">
Close
</Button>
</div>
</div> </div>
) : ( ) : (
<> <>
@ -381,10 +397,11 @@ const AlertsModal: FunctionComponent<AlertsModalProps> = ({
export default AlertsModal export default AlertsModal
const TelegramModal = ({ const TelegramModal = ({
tgCode, handleCloseModal,
handleCopyToClipboard, handleCopyToClipboard,
handleCloseTgCodeView, handleNewFromTgCode,
isCopied, isCopied,
tgCode,
}) => { }) => {
return ( return (
<div className="text-th-fgd-1"> <div className="text-th-fgd-1">
@ -417,9 +434,15 @@ const TelegramModal = ({
<li>Paste the code and send message</li> <li>Paste the code and send message</li>
</ol> </ol>
</div> </div>
<Button onClick={() => handleCloseTgCodeView()} className="w-full">
Okay, Got It <div className="flex pt-2 w-full">
<Button onClick={() => handleNewFromTgCode()} className="w-full mr-2">
New Alert
</Button> </Button>
<Button onClick={() => handleCloseModal()} className="w-full ml-2">
Close
</Button>
</div>
</div> </div>
) )
} }

View File

@ -146,7 +146,7 @@ export default function useWallet() {
if (connected && marginAccounts.length > 0) { if (connected && marginAccounts.length > 0) {
alertActions.loadAlerts(marginAccountsPublicKey) alertActions.loadAlerts(marginAccountsPublicKey)
} }
}, [marginAccounts]) }, [connected, marginAccounts])
useInterval(() => { useInterval(() => {
if (connected && marginAccount) { if (connected && marginAccount) {