-
Notifications
You must be signed in to change notification settings - Fork 49
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
14 changed files
with
666 additions
and
168 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import {NDKEvent} from '@nostr-dev-kit/ndk'; | ||
import {createContext, useCallback, useMemo, useRef, useState} from 'react'; | ||
|
||
import { KeyModalAction} from '../modules/KeyModal'; | ||
import {TipSuccessModal, TipSuccessModalProps} from '../modules/TipSuccessModal'; | ||
import { TokenCreateModal } from '../modules/TokenCreatedModal'; | ||
import { Modalize } from 'react-native-modalize'; | ||
|
||
export type TokenCreateModal = Modalize; | ||
|
||
export type TokenCreatedContextType = { | ||
show: (event?: NDKEvent, starknetAddress?: string) => void; | ||
hide?: () => void; | ||
|
||
showSuccess?: (props: TipSuccessModalProps) => void; | ||
hideSuccess?: () => void; | ||
}; | ||
|
||
export const TokenModalContext = createContext<TokenCreatedContextType | null>(null); | ||
|
||
export const TokenCreateModalProvider: React.FC<React.PropsWithChildren> = ({children}) => { | ||
const tokenModalRef = useRef<TokenCreateModal>(null); | ||
|
||
const [event, setEvent] = useState<NDKEvent | undefined>(); | ||
const [starknetAddress, setStarknetAddress] = useState<string | undefined>(); | ||
const [action, setAction] = useState<KeyModalAction | undefined>(); | ||
const [successModal, setSuccessModal] = useState<TipSuccessModalProps | null>(null); | ||
|
||
const show = useCallback((event?: NDKEvent, starknetAddress?: string, action?: KeyModalAction) => { | ||
setEvent(event); | ||
setStarknetAddress(starknetAddress); | ||
tokenModalRef.current?.open(); | ||
}, []); | ||
|
||
const hide = useCallback(() => { | ||
tokenModalRef.current?.close(); | ||
setEvent(undefined); | ||
}, []); | ||
|
||
const showSuccess = useCallback((props: TipSuccessModalProps) => { | ||
setSuccessModal(props); | ||
}, []); | ||
|
||
const hideSuccess = useCallback(() => { | ||
setSuccessModal(null); | ||
}, []); | ||
|
||
const context = useMemo( | ||
() => ({show, hide, showSuccess, hideSuccess}), | ||
[show, hide, showSuccess, hideSuccess], | ||
); | ||
return ( | ||
<TokenModalContext.Provider value={context}> | ||
{children} | ||
<TokenCreateModal | ||
starknetAddress={starknetAddress} | ||
event={event} | ||
show={show} | ||
hide={hide} | ||
showSuccess={showSuccess} | ||
hideSuccess={hideSuccess} | ||
ref={tokenModalRef} | ||
/> | ||
|
||
{successModal && <TipSuccessModal {...successModal} />} | ||
</TokenModalContext.Provider> | ||
); | ||
}; |
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,13 @@ | ||
import {useContext} from 'react'; | ||
|
||
import {TokenModalContext} from '../../context/TokenCreateModal'; | ||
|
||
export const useTokenCreatedModal = () => { | ||
const context = useContext(TokenModalContext); | ||
|
||
if (!context) { | ||
throw new Error('useTokenCreatedModal error with TokenModalContext'); | ||
} | ||
|
||
return context; | ||
}; |
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
Oops, something went wrong.