Skip to content

Commit

Permalink
modal + ui fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MSghais committed Aug 19, 2024
1 parent 63cb19f commit 3b1b11f
Show file tree
Hide file tree
Showing 14 changed files with 666 additions and 168 deletions.
65 changes: 46 additions & 19 deletions apps/mobile/src/app/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,25 +111,48 @@ const HomeBottomTabNavigator: React.FC = () => {
}}
/>

<HomeBottomTabsStack.Screen
name="UserProfile"
component={Profile as any}
initialParams={{ publicKey }}
options={{
tabBarActiveTintColor: 'white',
tabBarInactiveTintColor: 'grey',
tabBarIcon: ({ focused }) => (
<View style={styles.tabBarIcon}>
<Icon
name="UserIcon"
size={24}
color={focused ? 'bottomBarActive' : 'bottomBarInactive'}
/>
{focused && <Icon name="IndicatorIcon" color="primary" size={6} />}
</View>
),
}}
/>
{publicKey &&
<HomeBottomTabsStack.Screen
name="UserProfile"
component={Profile as any}
initialParams={{ publicKey }}
options={{
tabBarActiveTintColor: 'white',
tabBarInactiveTintColor: 'grey',
tabBarIcon: ({ focused }) => (
<View style={styles.tabBarIcon}>
<Icon
name="UserIcon"
size={24}
color={focused ? 'bottomBarActive' : 'bottomBarInactive'}
/>
{focused && <Icon name="IndicatorIcon" color="primary" size={6} />}
</View>
),
}}
/>
}

{!publicKey &&
<HomeBottomTabsStack.Screen
name="Login"
component={Login as any}
options={{
tabBarActiveTintColor: 'white',
tabBarInactiveTintColor: 'grey',
tabBarIcon: ({ focused }) => (
<View style={styles.tabBarIcon}>
<Icon
name="UserIcon"
size={24}
color={focused ? 'bottomBarActive' : 'bottomBarInactive'}
/>
{focused && <Icon name="IndicatorIcon" color="primary" size={6} />}
</View>
),
}}
/>
}
</HomeBottomTabsStack.Navigator>
);
};
Expand Down Expand Up @@ -205,6 +228,9 @@ const MainNavigator: React.FC = () => {
<DrawerStack.Screen name="Tips" component={Tips} />
<DrawerStack.Screen name="Settings" component={Settings} />
<DrawerStack.Screen name="LaunchDetail" component={LaunchDetail} />
<DrawerStack.Screen name="Auth" component={AuthNavigator} />
<DrawerStack.Screen name="Login" component={Login} />

</DrawerStack.Navigator>
);
};
Expand Down Expand Up @@ -264,6 +290,7 @@ const RootNavigator: React.FC = () => {

return (
<RootStack.Navigator screenOptions={{ headerShown: false }}>
{/* <RootStack.Screen name="MainStack" component={MainNavigator} /> */}
{publicKey ? (
<RootStack.Screen name="MainStack" component={MainNavigator} />
) : (
Expand Down
5 changes: 4 additions & 1 deletion apps/mobile/src/app/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { StarknetProvider } from './StarknetProvider';
import { TanstackProvider } from 'afk_nostr_sdk';
import { NostrProvider } from 'afk_nostr_sdk';
import { TipModalStarknetProvider } from '../context/TipModalStarknet';
import { TokenCreateModalProvider } from '../context/TokenCreateModal';
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: 2 } },
});
Expand All @@ -28,7 +29,9 @@ const ModalProviders = ({ children }: { children: React.ReactNode }) => {
<TransactionModalProvider>
<TipModalProvider>
<TipModalStarknetProvider>
<KeyModalProvider>{children}</KeyModalProvider>
<TokenCreateModalProvider>
<KeyModalProvider>{children}</KeyModalProvider>
</TokenCreateModalProvider>
</TipModalStarknetProvider>
</TipModalProvider>
</TransactionModalProvider>
Expand Down
68 changes: 68 additions & 0 deletions apps/mobile/src/context/TokenCreateModal.tsx
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>
);
};
2 changes: 1 addition & 1 deletion apps/mobile/src/hooks/api/indexer/useLaunchTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useGetTokenLaunch = () => {
queryKey: ['token_launch'],
queryFn: async () => {
const res = await ApiIndexerInstance.get('/deploy-launch');
console.log("res get launch",res)
// console.log("res get launch",res)
return res
},
});
Expand Down
13 changes: 13 additions & 0 deletions apps/mobile/src/hooks/modals/useTokenCreateModal.ts
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;
};
19 changes: 12 additions & 7 deletions apps/mobile/src/modules/LaunchTokenPump/FormLaunchToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { useAuth } from 'afk_nostr_sdk';
import { MainStackNavigationProps } from '../../types';
import { useAccount } from '@starknet-react/core';
import { useCreateToken, DeployTokenFormValues } from '../../hooks/launchpad/useCreateToken';
import { TipSuccessModalProps } from '../TipSuccessModal';
import { NDKEvent } from '@nostr-dev-kit/ndk';

const UsernameInputLeft = (
<Text weight="bold" color="inputPlaceholder">
Expand All @@ -27,15 +29,23 @@ enum TypeCreate {
CREATE,
CREATE_AND_LAUNCH
}
export type FormTokenCreatedProps = {
event?: NDKEvent;
starknetAddress?: string;
hide?: () => void;
showSuccess?: (props: TipSuccessModalProps) => void;
hideSuccess?: () => void;
};


type FormValues = DeployTokenFormValues;
export const FormLaunchToken: React.FC = () => {
export const FormLaunchToken: React.FC<FormTokenCreatedProps> = () => {
const formikRef = useRef<FormikProps<FormValues>>(null);
const styles = useStyles(stylesheet);
const publicKey = useAuth((state) => state.publicKey);
const profile = useProfile({ publicKey });
const queryClient = useQueryClient();
const { showToast } = useToast();
const navigation = useNavigation<MainStackNavigationProps>();
const account = useAccount()
const waitConnection = useWaitConnection()
const { deployToken, deployTokenAndLaunch } = useCreateToken()
Expand All @@ -58,7 +68,6 @@ export const FormLaunchToken: React.FC = () => {

const validateForm = (values: FormValues) => {
const errors = {} as Partial<FormValues>;

// TODO: Do validation

return errors;
Expand Down Expand Up @@ -144,14 +153,10 @@ export const FormLaunchToken: React.FC = () => {

<Button
onPress={() => onSubmitPress(TypeCreate.CREATE)}
// onPress={() => onSubmitPress}
>Create coin</Button>

<Button
// onPress={onSubmitPress}
onPress={() => onSubmitPress(TypeCreate.CREATE_AND_LAUNCH)}

// onPress={() => onSubmitPress}
>Create & Launch coin</Button>

<View style={styles.gap} />
Expand Down
73 changes: 44 additions & 29 deletions apps/mobile/src/modules/Layout/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,34 @@ import { Icon } from '../../../components/Icon';
import { useNavigation } from '@react-navigation/native';
import { DrawerStackNavigationProps, MainStackNavigationProps } from '../../../types';
// import { useAuth } from '../../../store/auth';
import { useAuth } from 'afk_nostr_sdk';
import { useAuth, useNostrContext } from 'afk_nostr_sdk';
import { DrawerNavigationHelpers } from '@react-navigation/drawer/lib/typescript/src/types';

interface SidebarInterface {
// navigation:MainStackNavigationProps | DrawerNavigationHelpers
navigation:any
navigation: any
}
const Sidebar = (
{navigation}:SidebarInterface
{ navigation }: SidebarInterface

) => {
const styles = useStyles(stylesheet);
const publicKey = useAuth((state) => state.publicKey);
const ndk = useNostrContext()
// const navigation = useNavigation<MainStackNavigationProps>()
// const navigation = useNavigation<DrawerStackNavigationProps>()
const handleNavigateProfile = () => {
navigation.navigate("Profile", { publicKey: publicKey });
};

const handleAuth = () => {
navigation.navigate("Auth");
};
const theme = useTheme()
// const handleNavigateHome = () => {
// navigation.navigate("Home");
// };
const handleDefiScreen = () => {
const handleDefiScreen = () => {
navigation.navigate("Defi");
};
const handleGameScreen = () => {
Expand All @@ -41,13 +46,13 @@ const Sidebar = (
const handleTipsScreen = () => {
navigation.navigate("Tips");
};
useEffect(() => {
const unsubscribe = navigation.addListener('drawerClose', () => {
// Code to handle drawer closing
});
useEffect(() => {
const unsubscribe = navigation.addListener('drawerClose', () => {
// Code to handle drawer closing
});

return unsubscribe;
}, [navigation]);
return unsubscribe;
}, [navigation]);

return (
<View style={styles.sidebar}>
Expand Down Expand Up @@ -103,7 +108,6 @@ const Sidebar = (

</Pressable>


<Pressable
onPress={handleGameScreen}
style={styles.item}>
Expand All @@ -118,7 +122,6 @@ const Sidebar = (

</Pressable>


<Pressable
onPress={handleDefiScreen}
style={styles.item}>
Expand All @@ -129,25 +132,37 @@ const Sidebar = (
<Text style={styles.textItem}>
Onramp & DeFI
</Text>

</Pressable>


<Pressable
onPress={handleNavigateProfile}
style={styles.item}>
<Icon
name="UserIcon"
size={24}
/>
<Text style={styles.textItem}>
Profile

</Text>

</Pressable>


{publicKey &&
<Pressable
onPress={handleNavigateProfile}
style={styles.item}>
<Icon
name="UserIcon"
size={24}
/>
<Text style={styles.textItem}>
Profile

</Text>
</Pressable>
}

{!publicKey && !ndk?.ndk?.signer &&
<Pressable
onPress={handleAuth}
style={styles.item}
>
<Icon
name="UserIcon"
size={24}
/>
<Text style={styles.textItem}>
Login
</Text>
</Pressable>
}

</View>
);
Expand Down
Loading

0 comments on commit 3b1b11f

Please sign in to comment.