Skip to content

Commit

Permalink
minor updates to oauth infra and spotify, github items
Browse files Browse the repository at this point in the history
  • Loading branch information
kibagateaux committed Dec 9, 2023
1 parent 7d6c428 commit dc017b1
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 60 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
parser: '@typescript-eslint/parser',
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
plugins: ['react-hooks'],
ignorePatterns: ['./*,js'], // dont lint config files
parserOptions: {
ecmaVersion: 2021,
sourceType: 'module',
Expand Down
16 changes: 16 additions & 0 deletions metro.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// eslint-disable-next-line
const { getDefaultConfig } = require('expo/metro-config');

/** @type {import('expo/metro-config').MetroConfig} */
const config = getDefaultConfig(__dirname);

module.exports = {
...config,
resolver: {
...config.resolver,
extraNodeModules: {
...config.resolver.extraNodeModules,
stream: require.resolve('react-native-stream'),
},
},
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"deploy:android": "eas build --platform android",
"deploy:secrets": "eas secret:push --scope jinni-health --env-file ./.env",
"ios": "expo run:ios",
"lint:dry": "eslint src/ .eslintrc.js --ext .ts,.tsx && prettier src/ --config .prettierrc --check",
"lint:fix": "eslint src/ --fix .eslintrc.js --ext .ts,.tsx && prettier src/ --config .prettierrc --write --ignore-unknown"
"lint:dry": "eslint ./src/ .eslintrc.js --ext .ts,.tsx && prettier ./src/ --config .prettierrc --check",
"lint:fix": "eslint ./src/ --fix .eslintrc.js --ext .ts,.tsx && prettier ./src/ --config .prettierrc --write --ignore-unknown"
},
"dependencies": {
"@apollo/client": "^3.8.6",
Expand Down
13 changes: 12 additions & 1 deletion src/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
import { View, StyleSheet } from 'react-native';
import { View, StyleSheet, Button } from 'react-native';
import { saveHomeConfig } from 'utils/config';

import { useHomeConfig } from 'hooks';
Expand All @@ -10,6 +10,7 @@ import { getIconForWidget } from 'utils/rendering';
import { AvatarViewer, WidgetIcon } from 'components/index';
import DefaultAvatar from 'assets/avatars/happy-ghost';
import WidgetContainer from 'components/home/WidgetContainer';
import { getActivityData } from 'utils/inventory/android-health-connect';

const HomeScreen = () => {
const { user } = useAuth();
Expand Down Expand Up @@ -53,11 +54,20 @@ const HomeScreen = () => {
/>
);
};

const onIntentionPress = async () => {
const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
const startTime = oneDayAgo.toISOString();
const endTime = now.toISOString();
await getActivityData({ startTime, endTime });
};
return (
<View style={{ flex: 1, ...useTheme() }}>
<View style={styles.container}>
<View style={styles.avatar}>
<AvatarViewer uri={homeConfig?.jinniImage} SVG={DefaultAvatar} />
<Button color="purple" title="Speak Intention" onPress={onIntentionPress} />
</View>

<WidgetContainer
Expand All @@ -73,6 +83,7 @@ const HomeScreen = () => {

const styles = StyleSheet.create({
container: {
backgroundColor: 'skyblue',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
Expand Down
5 changes: 3 additions & 2 deletions src/app/inventory/[item].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ const ItemPage: React.FC<ItemPageProps> = () => {
// hooks for items that require 3rd party authentication
const [itemOauthConfig, setItemOauth] = useState<OAuthProvider>(oauthConfigs.undefined);
const redirectUri = createOauthRedirectURI();
console.log('[OAUTH redirectUri]', redirectUri);
console.log('[OAUTH redirectUri]', `${redirectUri}?provider=${item?.id.toLowerCase()}`);
console.log('ITEM CONFIG: status', item?.status, status);

const [request, , promptAsync] = useAuthRequest(
{
clientId: itemOauthConfig.clientId,
scopes: itemOauthConfig.scopes,
redirectUri: `${redirectUri}?provider=${item?.id}`,
redirectUri: `${redirectUri}?provider=${item?.id.toLowerCase()}`,
usePKCE: false,
},
itemOauthConfig,
Expand Down Expand Up @@ -306,6 +306,7 @@ const ItemPage: React.FC<ItemPageProps> = () => {

const styles = StyleSheet.create({
container: {
backgroundColor: 'pink',
flex: 1,
padding: 25,
flexDirection: 'column',
Expand Down
14 changes: 11 additions & 3 deletions src/app/inventory/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useMemo, useState } from 'react';
import { Text, StyleSheet, SectionList, ActivityIndicator } from 'react-native';
import { Text, StyleSheet, SectionList, ActivityIndicator, View } from 'react-native';
import { groupBy, entries, map } from 'lodash/fp';

import { useInventory } from 'hooks';
Expand Down Expand Up @@ -58,6 +58,7 @@ const InventoryScreen: React.FC = () => {
style={styles.container}
// contentContainerStyle={styles.itemList}
sections={categorizedInventory}
ItemSeparatorComponent={() => <View style={styles.itemSeperator} />}
renderSectionHeader={renderCategoryHeader}
renderItem={({ item }) => renderItem({ item })}
/>
Expand All @@ -66,13 +67,16 @@ const InventoryScreen: React.FC = () => {

const styles = StyleSheet.create({
container: {
backgroundColor: 'pink',
flex: 1,
width: '100%',
},
inventoryHeader: {
fontSize: 20,
fontSize: 24,
fontWeight: 'bold',
margin: 25,
marginTop: 40,
marginBottom: 20,
marginLeft: 10, // same as list
},
itemList: {
flex: 1,
Expand All @@ -82,6 +86,10 @@ const styles = StyleSheet.create({
flexDirection: 'row',
justifyContent: 'flex-start',
},
itemSeperator: {
// TODO dope pink/blue wavy thing w/ screen pink background
margin: 20,
},
itemCard: {
flex: 1,
marginBottom: 18,
Expand Down
5 changes: 4 additions & 1 deletion src/components/common/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ const styles = StyleSheet.create({
// alignContent: 'center',
// textAlign: 'center',
},
cardContent: {},
cardContent: {
fontSize: 24,
fontWeight: '500',
},
image: {
width: 100,
height: 100,
Expand Down
29 changes: 0 additions & 29 deletions src/components/screens/(auth)/login.tsx

This file was deleted.

3 changes: 1 addition & 2 deletions src/types/GameMechanics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ export interface InventoryIntegration {
unequip: (helper?: HoF) => Promise<boolean>;
}

export type OAuthProviderIds = 'Spotify' | 'Coinbase' | 'Strava';
// TODO 'fitbit'export interface OAuthProviderConfig {
export type OAuthProviderIds = 'Spotify' | 'Github' | 'Coinbase' | 'Strava';

export interface OAuthProvider {
authorizationEndpoint: string;
Expand Down
3 changes: 2 additions & 1 deletion src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export const getGqlClient = () =>
}));

export const qu = (query: string) => (variables: object) =>
// strip /n and /t to prevent weird error converting to byte array on server side on ecrecvoer
getGqlClient().query({
query: gql`
${query}
${query.replace(/[\n\t]/g, ' ')}
`,
variables,
fetchPolicy: 'cache-first', // TODO add useCache: boolean to switch between query vs readQuery?
Expand Down
74 changes: 74 additions & 0 deletions src/utils/inventory/github.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import {
InventoryIntegration,
DjinnStat,
SpiritStat,
CommunityStat,
IntelligenceStat,
InventoryItem,
HoF,
} from 'types/GameMechanics';

const equip: HoF = async (promptAsync) => {
console.log('equipping github!!!');
try {
// expo-auth-session only exposes API via hooks which we cant embed in this since its a conditional call
// should we roll our own OAuth lib or just keep this callback method?
// Slightly complicates equip() vs no params but also enables a ton of functionality for any item
promptAsync!();
// TODO send mu(syncProvideId). If call fails then login unsuccessful
return true;
} catch (e) {
console.log('Inv:github:equip:ERR', e);
return false;
}
};

const unequip: HoF = async () => {
console.log('unequip github!!!');
try {
// TODO call api to delete identity
return true;
} catch (e) {
console.log('Inv:github:equip:ERR', e);
return false;
}
};

const item: InventoryItem = {
id: 'Github',
name: 'Octopus Brains',
datasource: 'Github',
image: 'https://pngimg.com/uploads/github/github_PNG90.png',
tags: ['digital', 'productivity'],
attributes: [
{ ...DjinnStat, value: 1 },
{ ...CommunityStat, value: 5 },
{ ...SpiritStat, value: 5 },
{ ...IntelligenceStat, value: 20 },
],
checkStatus: async () => {
// TODO api request to see if access_token exist on API
return 'unequipped';
},
canEquip: async () => true,
equip,
unequip,
abilities: [],
widgets: [],
};

const initPermissions = async () => {
return true;
};
const getPermissions = async () => {
return true;
};

export default {
item,
checkEligibility: async () => true,
equip,
unequip,
getPermissions,
initPermissions,
} as InventoryIntegration;
3 changes: 2 additions & 1 deletion src/utils/inventory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import iwatchHealth from './iwatch-health-kit';
import androidHealth from './android-health-connect';
import maliksMajik from './maliks-majik';
import spotify from './spotify';
import github from './github';
// import locationForeground from './phone-location-foreground';
// import locationBackground from './phone-location-background';

Expand Down Expand Up @@ -65,7 +66,7 @@ export const getInventoryItems = async (username?: string): Promise<InventoryIte
});
};

export const coreInventory = [maliksMajik.item, spotify.item];
export const coreInventory = [maliksMajik.item, spotify.item, github.item];
export const mobileInventory: InventoryItem[] = [
...coreInventory,
// locationForeground.item,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/inventory/maliks-majik.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HoF, ItemStatus } from 'types/GameMechanics';

import {
ID_ADDRESS_SLOT,
ID_PLAYER_SLOT,
ID_JINNI_SLOT,
PROOF_MALIKS_MAJIK_SLOT,
_delete_id,
Expand All @@ -17,7 +17,7 @@ import { MU_ACTIVATE_JINNI, mu } from 'utils/api';
const equip: HoF = async () => {
console.log("receiving Malik's Majik!!!");
try {
const address = await getStorage<string>(ID_ADDRESS_SLOT);
const address = await getStorage<string>(ID_PLAYER_SLOT);
console.log('address to get verified: ', address);
const result = address
? await signWithId(address)
Expand Down
21 changes: 11 additions & 10 deletions src/utils/inventory/spotify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
DjinnStat,
SpiritStat,
CommunityStat,
IntelligenceStat,
InventoryItem,
ItemStatus,
HoF,
Expand All @@ -15,7 +16,7 @@ const equip: HoF = async (promptAsync) => {
// should we roll our own OAuth lib or just keep this callback method?
// Slightly complicates equip() vs no params but also enables a ton of functionality for any item
promptAsync!();
// TODO how to know if they complete login + accept or if they cancel?
// TODO send mu(syncProvideId). If call fails then login unsuccessful
return true;
} catch (e) {
console.log('Inv:spotify:equip:ERR', e);
Expand All @@ -26,6 +27,7 @@ const equip: HoF = async (promptAsync) => {
const unequip: HoF = async () => {
console.log('unequip spotify!!!');
try {
// TODO call api to delete identity
return true;
} catch (e) {
console.log('Inv:spotify:equip:ERR', e);
Expand All @@ -35,20 +37,19 @@ const unequip: HoF = async () => {

const item: InventoryItem = {
id: 'Spotify',
name: "Da Bumpin Horn o' Vibranium",
name: "Horn o' Vibranium",
datasource: 'Spotify',
image: 'https://w7.pngwing.com/pngs/420/432/png-transparent-spotify-logo-spotify-computer-icons-podcast-music-apps-miscellaneous-angle-logo-thumbnail.png',
tags: ['digital', 'music', 'social'],
installLink: 'https://www.spotify.com/us/download/',
attributes: [
{ ...DjinnStat, value: 1 },
{ ...CommunityStat, value: 10 },
{ ...SpiritStat, value: 20 },
{ ...IntelligenceStat, value: 5 },
],
checkStatus: async () => {
// TODO figure out auth lol
// lookup local storage or server for access/refresh token
// const hasToken = await AsyncStorage.getItem('spotify-access-token');
// if(proof) return 'equipped';
// TODO api request to see if access_token exist on API
return 'unequipped';
},
canEquip: async () => true,
Expand Down Expand Up @@ -80,7 +81,6 @@ const item: InventoryItem = {
do: async () => {
// fetch your profile name from API (or maybe in user.identities.spotify?)
// pull up native share feature
//
return async () => true;
},
},
Expand All @@ -91,11 +91,12 @@ const item: InventoryItem = {
description: 'Create an IRL rave right now!',
canDo: async (status: ItemStatus) => (status === 'equipped' ? true : false),
do: async () => {
// find other devices on bluetooth network ?
// find local music?
// @DEV: Only Premium users can start Jams!
// find local music? (already done by spotify)
// find other devices on bluetooth network? (spotify lets u tap phones for bluetooth adding)
// how to make blended playlist without seding request to spotify?
// how to add music to playlist without sending request to spotify?

// No api for jams. Need to deeplink into app somehow
return async () => true;
},
},
Expand Down
Loading

0 comments on commit dc017b1

Please sign in to comment.