-
Notifications
You must be signed in to change notification settings - Fork 27
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
8 changed files
with
88 additions
and
35 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
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
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,46 @@ | ||
import { useCallback, useEffect } from 'react'; | ||
import { Modal, useModal } from 'src/components/menus/Modal'; | ||
import { StakeForm } from 'src/features/staking/StakeForm'; | ||
import { useStore } from 'src/features/store'; | ||
import { TxModalType } from 'src/features/transactions/types'; | ||
|
||
const TypeToComponent: Record<TxModalType, React.FC<any>> = { | ||
[TxModalType.Lock]: PlaceholderContent, | ||
[TxModalType.Unlock]: PlaceholderContent, | ||
[TxModalType.Withdraw]: PlaceholderContent, | ||
[TxModalType.Stake]: StakeForm, | ||
[TxModalType.Unstake]: PlaceholderContent, | ||
[TxModalType.Vote]: PlaceholderContent, | ||
[TxModalType.Unvote]: PlaceholderContent, | ||
[TxModalType.Delegate]: PlaceholderContent, | ||
[TxModalType.Undelegate]: PlaceholderContent, | ||
}; | ||
|
||
export function useTransactionModal(type: TxModalType, props?: any) { | ||
const setTxModal = useStore((state) => state.setTransactionModal); | ||
return useCallback(() => setTxModal({ type, props }), [setTxModal, type, props]); | ||
} | ||
|
||
export function TransactionModal() { | ||
const { isModalOpen, closeModal, openModal } = useModal(); | ||
|
||
const activeModal = useStore((state) => state.activeModal); | ||
const { type, props } = activeModal; | ||
|
||
const Component = type ? TypeToComponent[type] : PlaceholderContent; | ||
|
||
useEffect(() => { | ||
if (!openModal || !activeModal?.type) return; | ||
openModal(); | ||
}, [activeModal, openModal]); | ||
|
||
return ( | ||
<Modal isOpen={isModalOpen} close={closeModal}> | ||
<Component {...props} /> | ||
</Modal> | ||
); | ||
} | ||
|
||
function PlaceholderContent() { | ||
return <div className="flex items-center justify-center px-4 py-6">...</div>; | ||
} |
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,11 @@ | ||
export enum TxModalType { | ||
Lock = 'lock', | ||
Unlock = 'unlock', | ||
Withdraw = 'withdraw', | ||
Stake = 'stake', | ||
Unstake = 'unstake', | ||
Vote = 'vote', | ||
Unvote = 'unvote', | ||
Delegate = 'delegate', | ||
Undelegate = 'undelegate', | ||
} |
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