-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useState } from 'react'; | ||
import { Button } from '../ui/design-system/src/lib/Components/Button'; | ||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; | ||
import { faBrain } from '@fortawesome/free-solid-svg-icons'; | ||
import Modal from '@site/src/ui/design-system/src/lib/Components/Modal'; | ||
import { submitNoopChallenge } from '../utils/gold-star'; | ||
import * as fcl from '@onflow/fcl'; | ||
import { useProfile } from '../hooks/use-profile'; | ||
import { useCurrentUser } from '../hooks/use-current-user'; | ||
|
||
const ChallengeModal: React.FC<{ | ||
isOpen: boolean; | ||
onClose: () => void; | ||
}> = ({ isOpen, onClose }) => { | ||
const [txStatus, setTxStatus] = useState<string | null>(null); | ||
const { user } = useCurrentUser(); | ||
const { mutate: mutateProfile } = useProfile(user.addr); | ||
|
||
const completeChallenge = async () => { | ||
setTxStatus('Pending approval...'); | ||
try { | ||
const txId = await submitNoopChallenge(); | ||
|
||
setTxStatus('Submitting challenge...'); | ||
|
||
fcl | ||
.tx(txId) | ||
.onceSealed() | ||
.then(() => { | ||
mutateProfile(); | ||
}); | ||
|
||
await fcl.tx(txId).onceExecuted(); | ||
} catch (error) { | ||
console.error('Failed to complete challenge', error); | ||
} finally { | ||
setTxStatus(null); | ||
onClose(); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal isOpen={isOpen} onClose={onClose} title="Challenge Details"> | ||
<div className="space-y-4 text-center"> | ||
<FontAwesomeIcon icon={faBrain} size="5x" className="text-green-500" /> | ||
<p className="text-lg text-gray-700 mt-4"> | ||
By completing this challenge, you are declaring your intent to learn | ||
Flow and explore its capabilities. | ||
</p> | ||
<Button | ||
size="lg" | ||
className="w-full py-4 text-lg font-semibold mt-6" | ||
onClick={completeChallenge} | ||
disabled={txStatus !== null} | ||
> | ||
{txStatus ? txStatus : 'Complete Challenge'} | ||
</Button> | ||
</div> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ChallengeModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters