-
Notifications
You must be signed in to change notification settings - Fork 17
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
1 parent
18f19be
commit 4d34cdf
Showing
7 changed files
with
166 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { type FC, useCallback } from 'react'; | ||
import { | ||
Button, | ||
Modal, | ||
ModalContent, | ||
ModalHeader, | ||
ModalFooter, | ||
Typography, | ||
useCopyable, | ||
} from '@webb-tools/webb-ui-components'; | ||
import { QRScanLineIcon } from '@webb-tools/icons'; | ||
import { shortenHex } from '@webb-tools/webb-ui-components'; | ||
import { useReceiveModal } from '../hooks'; | ||
|
||
const ReceiveModal: FC = () => { | ||
const { copy, isCopied } = useCopyable(); | ||
const { isModalOpen, toggleModal, publicKey } = useReceiveModal(); | ||
|
||
const handleOpenChange = useCallback( | ||
(isOpen: boolean) => { | ||
toggleModal(isOpen); | ||
}, | ||
[toggleModal] | ||
); | ||
|
||
const closeModal = useCallback(() => { | ||
toggleModal(false); | ||
}, [toggleModal]); | ||
|
||
return ( | ||
<Modal open={isModalOpen} onOpenChange={handleOpenChange}> | ||
<ModalContent | ||
onCloseAutoFocus={closeModal} | ||
isOpen={isModalOpen} | ||
className="bg-mono-0 dark:bg-mono-180 w-full md:!w-[448px] rounded-2xl" | ||
isCenter | ||
> | ||
<ModalHeader onClose={closeModal} className=""> | ||
Receive | ||
</ModalHeader> | ||
|
||
<div className="flex flex-col gap-9 p-9"> | ||
<div className="flex gap-3"> | ||
<div> | ||
<QRScanLineIcon size="lg" /> | ||
</div> | ||
<div className=""> | ||
<Typography | ||
variant="body2" | ||
fw="bold" | ||
className="dark:text-mono-0" | ||
> | ||
Receiving Shielded Funds | ||
</Typography> | ||
<Typography variant="body2" className="dark:text-mono-0"> | ||
To receive shielded funds via transfers on the Hubble Bridge, | ||
simply copy and share your shielded account public key. This | ||
unique identifier allows others to transfer spend notes to your | ||
account. | ||
</Typography> | ||
</div> | ||
</div> | ||
<div className="rounded-lg p-4 bg-mono-20 dark:bg-mono-160 flex items-center justify-between gap-1"> | ||
<Typography variant="body1" className="dark:text-mono-0"> | ||
Account Public Key: | ||
</Typography> | ||
<Typography variant="body1" className="dark:text-mono-0"> | ||
{publicKey ? shortenHex(publicKey, 5) : '--'} | ||
</Typography> | ||
</div> | ||
</div> | ||
|
||
<ModalFooter> | ||
{publicKey !== undefined && ( | ||
<Button | ||
isFullWidth | ||
onClick={() => { | ||
copy(publicKey); | ||
}} | ||
> | ||
{isCopied ? 'Copied!' : 'Click to copy'} | ||
</Button> | ||
)} | ||
<Button variant="secondary" isFullWidth> | ||
Learn More | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default ReceiveModal; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
import { useObservableState } from 'observable-hooks'; | ||
import { useWebContext } from '@webb-tools/api-provider-environment'; | ||
|
||
import subjects from './subjects'; | ||
|
||
export type UseReceiveModalReturnType = { | ||
/** | ||
* Boolean to check if the receive modal is open | ||
*/ | ||
isModalOpen: boolean; | ||
|
||
/** | ||
* Toggle or set state of the wallet modal | ||
*/ | ||
toggleModal: (isOpen?: boolean) => void; | ||
|
||
/** | ||
* Public key of current account | ||
*/ | ||
publicKey?: string; | ||
}; | ||
|
||
const useReceiveModal = (): UseReceiveModalReturnType => { | ||
const isModalOpen = useObservableState(subjects.isReceiveModalOpenSubject); | ||
|
||
const { noteManager } = useWebContext(); | ||
|
||
/** | ||
* Toggle or set state of the wallet modal | ||
*/ | ||
const toggleModal = useCallback((isOpenArg?: boolean) => { | ||
const isOpen = isOpenArg ?? !subjects.isReceiveModalOpenSubject.getValue(); | ||
|
||
subjects.setReceiveModalOpen(isOpen); | ||
}, []); | ||
|
||
const publicKey = useMemo( | ||
() => noteManager?.getKeypair().toString(), | ||
[noteManager] | ||
); | ||
|
||
return { | ||
isModalOpen, | ||
toggleModal, | ||
publicKey, | ||
}; | ||
}; | ||
|
||
export default useReceiveModal; |
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,10 @@ | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
const isReceiveModalOpenSubject = new BehaviorSubject<boolean>(false); | ||
const setReceiveModalOpen = (isOpen: boolean) => | ||
isReceiveModalOpenSubject.next(isOpen); | ||
|
||
export default { | ||
isReceiveModalOpenSubject, | ||
setReceiveModalOpen, | ||
}; |
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