Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint features/fix #18

Merged
merged 8 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/mobile/src/app/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Games } from '../screens/Games';
import { useAuth } from 'afk_nostr_sdk';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { Navbar } from '../components/Navbar';
import { Settings } from '../screens/Settings';

const DrawerStack = createDrawerNavigator<MainStackParams>();
const RootStack = createNativeStackNavigator<RootStackParams>();
Expand Down Expand Up @@ -202,6 +203,7 @@ const MainNavigator: React.FC = () => {
<DrawerStack.Screen name="Defi" component={Defi} />
<DrawerStack.Screen name="Games" component={Games} />
<DrawerStack.Screen name="Tips" component={Tips} />
<DrawerStack.Screen name="Settings" component={Settings} />
</DrawerStack.Navigator>
);
};
Expand Down
9 changes: 6 additions & 3 deletions apps/mobile/src/app/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ import { WalletModalProvider } from '../context/WalletModal';
import App from './App';
import { StarknetProvider } from './StarknetProvider';
// import { NostrProvider } from '../context/NostrContext';
import {TanstackProvider} from 'afk_nostr_sdk';
import {NostrProvider} from 'afk_nostr_sdk';
import { TanstackProvider } from 'afk_nostr_sdk';
import { NostrProvider } from 'afk_nostr_sdk';
import { TipModalStarknetProvider } from '../context/TipModalStarknet';
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: 2 } },
});
Expand All @@ -26,7 +27,9 @@ const ModalProviders = ({ children }: { children: React.ReactNode }) => {
<WalletModalProvider>
<TransactionModalProvider>
<TipModalProvider>
<KeyModalProvider>{children}</KeyModalProvider>
<TipModalStarknetProvider>
<KeyModalProvider>{children}</KeyModalProvider>
</TipModalStarknetProvider>
</TipModalProvider>
</TransactionModalProvider>
</WalletModalProvider>
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/assets/icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Svg, { G, Path, Rect, SvgProps } from 'react-native-svg';
export const AddPostIcon: React.FC<SvgProps> = (props) => (
<Svg viewBox="0 0 72 72" fill="none" {...props}>
<Path
fill="#EC796B"
fill="currentColor"
d="M30 3.464a12 12 0 0 1 12 0l19.177 11.072a12 12 0 0 1 6 10.392v22.144a12 12 0 0 1-6 10.392L42 68.536a12 12 0 0 1-12 0L10.823 57.464a12 12 0 0 1-6-10.392V24.928a12 12 0 0 1 6-10.392L30 3.464Z"
/>
<Path
Expand Down
53 changes: 53 additions & 0 deletions apps/mobile/src/components/HeaderScreen/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { Image, View } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';

import { useStyles, useTheme } from '../../hooks';
import { Text } from '../Text';
import stylesheet from './styles';
import { AFKIcon } from '../../assets/icons';

export type HeaderProps = {
showLogo?: boolean;
left?: React.ReactNode;
right?: React.ReactNode;
title?: string;
};

export const HeaderScreen: React.FC<HeaderProps> = ({ showLogo = true, left, right, title }) => {
const { theme } = useTheme();
const styles = useStyles(stylesheet);

return (
<SafeAreaView edges={['top', 'left', 'right']} style={styles.container}>
<View style={styles.content}>
{left}

{showLogo && (
<View style={styles.logoContainer}>
<Image
style={styles.logo}
source={require('../../assets/pepe-logo.png')}
/>
{/* <AFKIcon color={theme.colors.text} width={96} height={16} /> */}
</View>
)}

{title && (
<View style={styles.title}>
<Text weight="bold" color="textStrong" align="center" fontSize={18}>
{title}
</Text>
</View>
)}

{right}

{/* {right ?? (
<View style={styles.buttons}>
<IconButton icon="BellIcon" size={20} />
</View>
)} */}
</View>
</SafeAreaView>
);
};
37 changes: 37 additions & 0 deletions apps/mobile/src/components/HeaderScreen/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {StyleSheet} from 'react-native';

import {Spacing, ThemedStyleSheet} from '../../styles';

export default ThemedStyleSheet((theme) => ({
container: {
},
content: {
width: '100%',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingVertical: Spacing.xxsmall,
paddingHorizontal: Spacing.medium,
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: theme.colors.divider,
},

logoContainer: {
flexDirection: 'row',
alignItems: 'center',
},
logo: {
width: 40,
height: 40,
marginRight: Spacing.xsmall,
},

title: {
flex: 1,
},

buttons: {
flexDirection: 'row',
alignItems: 'center',
},
}));
6 changes: 5 additions & 1 deletion apps/mobile/src/components/Modalize/styles.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import {Platform} from 'react-native';
import {Dimensions, Platform} from 'react-native';

import {Spacing, ThemedStyleSheet} from '../../styles';

export default ThemedStyleSheet((theme) => ({
modal: {
backgroundColor: theme.colors.surface,
// width:Dimensions.get("window").width >= 1024 ? 300 : "100%",
// flex: 1,
// justifyContent: 'center',
// alignItems: 'center'
},

header: {
Expand Down
189 changes: 189 additions & 0 deletions apps/mobile/src/components/TokenLaunchCard/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
import { NDKEvent, NDKUserProfile } from '@nostr-dev-kit/ndk';
import { useNavigation } from '@react-navigation/native';
import { Image, ImageSourcePropType, Pressable, TextInput, View, } from 'react-native';

// import {useProfile} from '../../hooks';
import { MainStackNavigationProps } from '../../types';
import { Text } from '../Text';
import { useProfile } from "afk_nostr_sdk"
import { KeysUser, TokenLaunchInterface } from '../../types/keys';
import { Fraction } from '@uniswap/sdk-core';
import { decimalsScale } from '../../utils/helpers';
import { cairo, uint256 } from 'starknet';
import { feltToAddress } from '../../utils/format';
import { useSellKeys } from '../../hooks/keys/useSellKeys';
import { useBuyKeys } from '../../hooks/keys/useBuyKeys';
import { useAccount } from '@starknet-react/core';
import { useState } from 'react';
import { Button } from '../Button';
import stylesheet from './styles';
import { useStyles, useWaitConnection } from '../../hooks';
import { useWalletModal } from '../../hooks/modals';
import { Input } from '../Input';

export type LaunchCoinProps = {
imageProps?: ImageSourcePropType;
name?: string;
event?: NDKEvent;
profileProps?: NDKUserProfile;
launch?: TokenLaunchInterface
};

enum AmountType {
QUOTE_AMOUNT,
COIN_AMOUNT_TO_BUY
}
export const TokenLaunchCard: React.FC<LaunchCoinProps> = ({ launch, imageProps, name, profileProps, event }) => {
const { data: profile } = useProfile({ publicKey: event?.pubkey });
const account = useAccount()

const styles = useStyles(stylesheet)

const [amount, setAmount] = useState<number | undefined>()
const [typeAmount, setTypeAmount] = useState<AmountType>(AmountType.QUOTE_AMOUNT)

const { handleSellKeys } = useSellKeys()
const { handleBuyKeys } = useBuyKeys()
const waitConnection = useWaitConnection();
const walletModal = useWalletModal();

const onConnect = async () => {
if (!account.address) {
walletModal.show();

const result = await waitConnection();
if (!result) return;
}
};
const sellKeys = async () => {
if (!amount) return;

await onConnect()
if (!account || !account?.account) return;

if (!launch?.owner) return;

if (!launch?.token_quote) return;

// handleSellKeys(account?.account, launch?.owner, Number(amount), launch?.token_quote, undefined)
handleSellKeys(account?.account, feltToAddress(BigInt(launch?.owner)), Number(amount), launch?.token_quote, undefined)

}

const buyCoin = async () => {
if (!amount) return;

await onConnect()

if (!account || !account?.account) return;

if (!launch?.owner) return;

if (!launch?.token_quote) return;
// handleBuyKeys(account?.account, launch?.owner, launch?.token_quote, Number(amount),)
handleBuyKeys(account?.account, feltToAddress(BigInt(launch?.owner)), Number(amount), launch?.token_quote,)
}
const navigation = useNavigation<MainStackNavigationProps>();
// const handleNavigateToProfile = () => {
// if (!event?.id) return;
// navigation.navigate('Profile', { publicKey: event?.pubkey });
// };
let priceAmount;
if (launch?.price) {
priceAmount = new Fraction(String(launch.price), decimalsScale(18)).toFixed(18);
}
let created_at;

if (launch?.created_at) {
created_at = new Fraction(String(launch.created_at), decimalsScale(18)).toFixed(18);

}

return (
<View style={styles.container}>
<View>

{launch?.owner &&
<Text>
Owner: {feltToAddress(BigInt(launch.owner))}

</Text>
}
{/*
<View style={styles.imageContainer}>
<Image
source={
profile?.cover ? profile?.cover : require('../../../assets/feed/images/story-bg.png')
}
resizeMode="cover"
/>
<Image
style={styles.image}
source={profile?.image ? profile?.image : require('../../assets/degen-logo.png')}
/>
<Text weight="medium" fontSize={13} style={styles.name}>
{profile?.name ?? profile?.nip05 ?? profile?.displayName ?? 'Anon AFK'}
</Text>
</View> */}
<Text>
Supply: {Number(launch?.total_supply) / 10 ** 18}
</Text>
<Text>
Supply: {Number(launch?.total_supply)}
</Text>
<Text>
Price: {Number(launch?.price) / 10 ** 18}
</Text>

{/* {launch?.created_at &&
<Text>
Created at {Number(launch?.created_at) / 10 ** 18}
</Text>
} */}

</View>

{launch?.token_quote &&
<View
style={styles.imageContainer}
>
<Text>Token quote</Text>
<Text>
Quote token: {feltToAddress(BigInt(launch.token_quote?.token_address))}
</Text>
<Text>
Step increase: {Number(launch.token_quote?.step_increase_linear) / 10 ** 18}
</Text>
</View>}

<Input

keyboardType='numeric'
value={amount ? String(amount) : "0"} onChangeText={(e) => {
setAmount(Number(e))
// if (e && Number(e) ) {
// setAmount(Number(e))
// }

// if (e ) {
// setAmount(Number(0))
// }
}} placeholder="Amount" />
<View style={{ display: "flex", flex: 1, flexDirection: "row", gap: 3 }}>

<Button onPress={buyCoin} style={{ backgroundColor: "green" }} >
<Text>
Buy
</Text>
</Button>

<Button onPress={sellKeys}

style={{ backgroundColor: "red" }}>
Sell

</Button>
</View>
</View>
);
};
30 changes: 30 additions & 0 deletions apps/mobile/src/components/TokenLaunchCard/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Spacing, ThemedStyleSheet } from '../../styles';
export default ThemedStyleSheet((theme) => ({
container: {
// alignItems: 'center',
backgroundColor: theme.colors.surface,
padding: Spacing.xsmall,
borderRadius: 8,
gap: Spacing.xsmall,
overflowWrap:"break-word",
width:300,
},
imageContainer: {
// position: 'relative',
// display: 'flex',
// alignItems: 'center',
// justifyContent: 'center',
borderRadius: 15
},
text:{
},
image: {
position: 'absolute',
width: 35,
height: 35,
borderRadius: 15
},
name: {
paddingTop: Spacing.xxsmall,
},
}))
10 changes: 10 additions & 0 deletions apps/mobile/src/constants/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ export const UNRUGGABLE_FACTORY_ADDRESS = {

// [constants.StarknetChainId.SN_SEPOLIA]: "0x5e89dc74f1a40d7814966b028a9b1853d39006a954b27828a9de7e333ec8119",
};

export const NAMESPACE_ADDRESS = {
[constants.StarknetChainId.SN_SEPOLIA]:"0x6e8ecfa6872bd27a7517077069b401a494687e66e2a98d37311eee1d96f1b57",
[constants.StarknetChainId.SN_MAIN]:""
}

export const LAUNCHPAD_ADDRESS = {
[constants.StarknetChainId.SN_SEPOLIA]:"0x517110eac4a6e8a50a0966b386a3b19f1facf96a8adb393594a52edf6e9fcc7",
[constants.StarknetChainId.SN_MAIN]:"",
}
Loading
Loading