Skip to content

Commit

Permalink
feat: Wallet Connect integration (keep-starknet-strange#177)
Browse files Browse the repository at this point in the history
* wallet connect integration

* Rename Modal to Dialog

* Modal component

* Wallet Modal

* Wallet QR Modal

* Add todo

* Fix dependencies

* Regenerate yarn lockfile

* Remove dependency check
  • Loading branch information
ugur-eren authored Jun 17, 2024
1 parent 2c03f39 commit ffc375b
Show file tree
Hide file tree
Showing 22 changed files with 2,310 additions and 734 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/joyboy-community.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ jobs:
- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Dependencies Check
run: yarn check

- name: Prettier Format Check
run: yarn format:check

Expand Down
7 changes: 7 additions & 0 deletions JoyboyCommunity/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
"@react-navigation/native": "^6.1.17",
"@react-navigation/native-stack": "^6.9.26",
"@react-navigation/stack": "^6.3.29",
"@starknet-wc/react": "0.0.2",
"@starknet-react/chains": "^0.1.7",
"@starknet-react/core": "^2.8.2",
"@tanstack/react-query": "^5.40.0",
"buffer": "^6.0.3",
"crypto-es": "^2.1.0",
Expand All @@ -35,11 +38,13 @@
"expo-clipboard": "~6.0.3",
"expo-crypto": "~13.0.2",
"expo-image-picker": "~15.0.5",
"expo-linking": "~6.3.1",
"expo-secure-store": "~13.0.1",
"expo-splash-screen": "~0.27.4",
"expo-status-bar": "~1.12.1",
"fast-text-encoding": "^1.0.6",
"formik": "^2.4.6",
"get-starknet-core": "^3.3.0",
"memoize-one": "^6.0.0",
"pbkdf2": "^3.1.2",
"react": "18.2.0",
Expand All @@ -50,12 +55,14 @@
"react-native-modalize": "^2.1.1",
"react-native-pager-view": "6.3.0",
"react-native-portalize": "^1.0.7",
"react-native-qrcode-svg": "^6.3.1",
"react-native-reanimated": "~3.10.1",
"react-native-safe-area-context": "^4.8.2",
"react-native-screens": "^3.29.0",
"react-native-svg": "^15.3.0",
"react-native-tab-view": "^3.5.2",
"react-native-web": "~0.19.6",
"starknet": "^5.24.3",
"styled-components": "^6.1.11",
"zustand": "^4.5.2"
},
Expand Down
3 changes: 2 additions & 1 deletion JoyboyCommunity/src/app/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {EditProfile} from '../screens/EditProfile';
import {Feed} from '../screens/Feed';
import {PostDetail} from '../screens/PostDetail';
import {Profile} from '../screens/Profile';
import {WalletConnect} from '../screens/WalletConnect';
import {useAuth} from '../store/auth';
import {AuthStackParams, HomeBottomStackParams, MainStackParams, RootStackParams} from '../types';

Expand Down Expand Up @@ -77,7 +78,7 @@ const HomeBottomTabNavigator: React.FC = () => {

<HomeBottomTabsStack.Screen
name="Messages"
component={Profile}
component={WalletConnect}
options={{
tabBarActiveTintColor: 'white',
tabBarInactiveTintColor: 'grey',
Expand Down
60 changes: 60 additions & 0 deletions JoyboyCommunity/src/app/StarknetProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import {mainnet} from '@starknet-react/chains';
import {
argent,
braavos,
publicProvider,
StarknetConfig,
useInjectedConnectors,
voyager,
} from '@starknet-react/core';
import {
ConnectorProvider as StarknetWCProvider,
useArgentMobileConnector,
} from '@starknet-wc/react';
import {Platform} from 'react-native';
import {constants} from 'starknet';

import {WalletQRModal} from '../modules/WalletQRModal';

export const StarknetReactProvider: React.FC<React.PropsWithChildren> = ({children}) => {
const {connectors} = useInjectedConnectors({
// Show these connectors if the user has no connector installed.
recommended: [argent(), braavos()],
// Hide recommended connectors if the user has any connector installed.
includeRecommended: 'onlyIfNoConnectors',
// Randomize the order of the connectors.
order: 'random',
});

const argentMobileConnector = useArgentMobileConnector();

return (
<StarknetConfig
chains={[mainnet]}
provider={publicProvider()}
connectors={[
argentMobileConnector({
chain: constants.NetworkName.SN_MAIN,
// TODO: Move this to ENV
wcProjectId: 'a9b4b052eb741f95a54c90ac5bdb343e',
dappName: 'Joyboy',
description: 'Joyboy Starknet dApp',
url: 'https://joyboy.community',
}),

...(Platform.OS === 'web' ? connectors : []),
]}
explorer={voyager}
>
{children}
</StarknetConfig>
);
};

export const StarknetProvider: React.FC<React.PropsWithChildren> = ({children}) => {
return (
<StarknetWCProvider modal={WalletQRModal}>
<StarknetReactProvider>{children}</StarknetReactProvider>
</StarknetWCProvider>
);
};
12 changes: 9 additions & 3 deletions JoyboyCommunity/src/app/Wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {ThemeProvider as StyledThemeProvider} from 'styled-components/native';
import {RootScreenContainer} from '../components';
import {NostrProvider} from '../context/NostrContext';
import {ThemeProvider} from '../context/Theme';
import {WalletModalProvider} from '../context/WalletModal';
import {darkModeColors, lightModeColors} from '../tokens/colors';
import App from './App';
import {StarknetProvider} from './StarknetProvider';

const queryClient = new QueryClient({
defaultOptions: {queries: {retry: 2}},
Expand All @@ -34,9 +36,13 @@ export const Wrapper: React.FC = () => {
<NostrProvider>
<QueryClientProvider client={queryClient}>
<PortalizeProvider>
<RootScreenContainer>
<App />
</RootScreenContainer>
<StarknetProvider>
<WalletModalProvider>
<RootScreenContainer>
<App />
</RootScreenContainer>
</WalletModalProvider>
</StarknetProvider>
</PortalizeProvider>
</QueryClientProvider>
</NostrProvider>
Expand Down
66 changes: 66 additions & 0 deletions JoyboyCommunity/src/components/Dialog/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react';
import {View} from 'react-native';
import {Portal} from 'react-native-portalize';

import {useStyles} from '../../hooks';
import {Button, ButtonProps} from '../Button';
import {Text} from '../Text';
import stylesheet from './styles';

export type DialogProps = {
title: string;
description: string;
icon?: React.ReactNode;
visible?: boolean;
buttons: {
label: string;
type: ButtonProps['variant'];
onPress: () => void;
}[];
};

export const Dialog: React.FC<DialogProps> = ({
title,
icon,
description,
visible = true,
buttons,
}) => {
const styles = useStyles(stylesheet);

if (!visible) return null;

return (
<Portal>
<View style={styles.container}>
<View style={styles.modal}>
<View style={styles.content}>
{icon && <View style={styles.icon}>{icon}</View>}

<Text weight="bold" fontSize={21} lineHeight={24} style={styles.title}>
{title}
</Text>

<Text
weight="semiBold"
color="textSecondary"
align="center"
fontSize={15}
lineHeight={20}
>
{description}
</Text>
</View>

<View style={styles.buttons}>
{buttons.map((button, index) => (
<Button key={index.toString()} block variant={button.type} onPress={button.onPress}>
{button.label}
</Button>
))}
</View>
</View>
</View>
</Portal>
);
};
39 changes: 39 additions & 0 deletions JoyboyCommunity/src/components/Dialog/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {Spacing, ThemedStyleSheet} from '../../styles';

export default ThemedStyleSheet((theme) => ({
container: {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: 'rgba(0, 0, 0, 0.4)',
alignItems: 'center',
justifyContent: 'center',
paddingHorizontal: Spacing.xlarge,
},
modal: {
width: '100%',
backgroundColor: theme.colors.surface,
padding: Spacing.large,
borderRadius: 24,
},

content: {
alignItems: 'center',
},
icon: {
marginTop: Spacing.xsmall,
marginBottom: Spacing.large,
},
title: {
marginBottom: Spacing.medium,
},

buttons: {
gap: Spacing.xsmall,
marginTop: Spacing.xlarge,
},
}));
58 changes: 10 additions & 48 deletions JoyboyCommunity/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,26 @@
import React from 'react';
import {View} from 'react-native';
import {View, ViewProps} from 'react-native';
import {Portal} from 'react-native-portalize';

import {useStyles} from '../../hooks';
import {Button, ButtonProps} from '../Button';
import {Text} from '../Text';
import stylesheet from './styles';

export type ModalProps = {
title: string;
description: string;
icon?: React.ReactNode;
visible?: boolean;
buttons: {
label: string;
type: ButtonProps['variant'];
onPress: () => void;
}[];
export type ModalProps = ViewProps & {
containerProps?: ViewProps;
};

export const Modal: React.FC<ModalProps> = ({
title,
icon,
description,
visible = true,
buttons,
containerProps,
style: styleProp,
children,
...modalProps
}) => {
const styles = useStyles(stylesheet);

if (!visible) return null;

return (
<Portal>
<View style={styles.container}>
<View style={styles.modal}>
<View style={styles.content}>
{icon && <View style={styles.icon}>{icon}</View>}

<Text weight="bold" fontSize={21} lineHeight={24} style={styles.title}>
{title}
</Text>

<Text
weight="semiBold"
color="textSecondary"
align="center"
fontSize={15}
lineHeight={20}
>
{description}
</Text>
</View>

<View style={styles.buttons}>
{buttons.map((button, index) => (
<Button key={index.toString()} block variant={button.type} onPress={button.onPress}>
{button.label}
</Button>
))}
</View>
<View style={[styles.container, containerProps?.style]} {...containerProps}>
<View style={[styles.modal, styleProp]} {...modalProps}>
{children}
</View>
</View>
</Portal>
Expand Down
23 changes: 4 additions & 19 deletions JoyboyCommunity/src/components/Modal/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,21 @@ export default ThemedStyleSheet((theme) => ({
container: {
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
left: 0,
width: '100%',
height: '100%',
backgroundColor: 'rgba(0, 0, 0, 0.4)',
alignItems: 'center',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: theme.colors.overlay,
paddingHorizontal: Spacing.xlarge,
},

modal: {
width: '100%',
backgroundColor: theme.colors.surface,
padding: Spacing.large,
borderRadius: 24,
},

content: {
alignItems: 'center',
},
icon: {
marginTop: Spacing.xsmall,
marginBottom: Spacing.large,
},
title: {
marginBottom: Spacing.medium,
},

buttons: {
gap: Spacing.xsmall,
marginTop: Spacing.xlarge,
},
}));
1 change: 1 addition & 0 deletions JoyboyCommunity/src/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export {Avatar} from './Avatar';
export {Button} from './Button';
export {Dialog} from './Dialog';
export {Divider} from './Divider';
export {Header} from './Header';
export {IconButton} from './IconButton';
Expand Down
Loading

0 comments on commit ffc375b

Please sign in to comment.