Skip to content

Commit

Permalink
chore: add example app to rn-base (#1171)
Browse files Browse the repository at this point in the history
* fix: fix linting and spacing issues

* feat: remove package hoisting from example project

* fix: fix linting and spacing issues

* feat: add signer authentication sample implementation in example app

* feat: add tsx to handle server instantiation

* feat: update peer-dependencies for signer package

---------

Co-authored-by: Iyk Azorji <[email protected]>
  • Loading branch information
moldy530 and iykazrji committed Nov 22, 2024
1 parent f67c5e0 commit 931346f
Show file tree
Hide file tree
Showing 21 changed files with 668 additions and 133 deletions.
2 changes: 1 addition & 1 deletion aa-sdk/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"registry": "https://registry.npmjs.org/"
},
"scripts": {
"prebuild": "npx tsx ./inject-version.ts",
"prebuild": "tsx ./inject-version.ts",
"build": "yarn clean && yarn build:esm && yarn build:types",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
"build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
Expand Down
2 changes: 1 addition & 1 deletion account-kit/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"./package.json": "./package.json"
},
"scripts": {
"prebuild": "npx tsx ./inject-version.ts",
"prebuild": "tsx ./inject-version.ts",
"build": "yarn clean && yarn build:esm && yarn build:types",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
"build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
Expand Down
2 changes: 1 addition & 1 deletion account-kit/infra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"./package.json": "./package.json"
},
"scripts": {
"prebuild": "npx tsx ./inject-version.ts",
"prebuild": "tsx ./inject-version.ts",
"build": "yarn clean && yarn build:esm && yarn build:types",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
"build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
Expand Down
4 changes: 2 additions & 2 deletions account-kit/logging/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@
"./package.json": "./package.json"
},
"scripts": {
"prebuild": "npx tsx ./prebuild.ts",
"prebuild": "tsx ./prebuild.ts",
"build": "yarn clean && yarn build:esm && yarn build:types",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
"build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"postbuild": "npx tsx ./postbuild.ts",
"postbuild": "tsx ./postbuild.ts",
"clean": "rm -rf ./dist",
"test": "vitest --passWithNoTests",
"test:run": "vitest run --passWithNoTests"
Expand Down
2 changes: 1 addition & 1 deletion account-kit/plugingen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"plugingen": "./dist/esm/cli.js"
},
"scripts": {
"prebuild": "npx tsx ./inject-version.ts",
"prebuild": "tsx ./inject-version.ts",
"build": "yarn clean && yarn build:esm && yarn build:types",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
"build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
Expand Down
2 changes: 1 addition & 1 deletion account-kit/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"./package.json": "./package.json"
},
"scripts": {
"prebuild": "npx tsx ./inject-version.ts",
"prebuild": "tsx ./inject-version.ts",
"dev": "storybook dev",
"build": "yarn clean && yarn build:esm && yarn build:types",
"build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".MainApplication"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
android:allowBackup="false"
android:theme="@style/AppTheme"
android:supportsRtl="true">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<uses-permission android:name="android.permission.INTERNET"/>
<application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="false" android:theme="@style/AppTheme" android:supportsRtl="true">
<activity android:name=".MainActivity" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
<data android:scheme="rn-signer-demo"/>
</intent-filter>
</activity>
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ import com.facebook.react.ReactActivity
import com.facebook.react.ReactActivityDelegate
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
import com.facebook.react.defaults.DefaultReactActivityDelegate
import android.os.Bundle

class MainActivity : ReactActivity() {

// Necessary for react-native-screens
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(null)
}
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
Expand Down
27 changes: 23 additions & 4 deletions account-kit/rn-signer/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,35 @@
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"android": "react-native run-android && yarn start:redirect-server",
"ios": "react-native run-ios",
"start": "react-native start",
"start:redirect-server": "tsx ./redirect-server/index.ts",
"build:android": "react-native build-android --extra-params \"--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a\"",
"build:ios": "react-native build-ios --scheme ReactNativeSignerExample --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\""
},
"dependencies": {
"@account-kit/signer": "^4.3.0",
"@react-navigation/native": "7.0.3",
"@react-navigation/native-stack": "7.1.0",
"dotenv": "^16.4.5",
"express": "^4.21.1",
"react": "18.3.1",
"react-native": "0.76.1",
"react-native-config": "^1.5.3",
"react-native-mmkv": "^3.1.0",
"react-native-config": "1.5.3",
"react-native-gesture-handler": "2.21.2",
"react-native-mmkv": "3.1.0",
"react-native-safe-area-context": "4.14.0",
"react-native-screens": "4.2.0",
"util": "^0.12.5",
"viem": "^2.21.41",
"zustand": "^5.0.1"
},
"peerDependencies": {
"@types/react": "18.3.1",
"react": "18.3.1",
"react-native": "0.76.1"
},
"devDependencies": {
"@babel/core": "^7.25.2",
"@babel/preset-env": "^7.25.3",
Expand All @@ -29,9 +42,15 @@
"@react-native/babel-preset": "0.76.1",
"@react-native/metro-config": "0.76.1",
"@react-native/typescript-config": "0.76.1",
"react-native-builder-bob": "^0.30.3"
"react-native-builder-bob": "^0.30.3",
"tsx": "^4.19.2"
},
"engines": {
"node": ">=18"
},
"workspaces": {
"nohoist": [
"**"
]
}
}
19 changes: 19 additions & 0 deletions account-kit/rn-signer/example/redirect-server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import express from "express";
import dotenv from "dotenv";

dotenv.config();

const app = express();
const port = process.env.PORT || 5500;
const appScheme = process.env.APP_SCHEME || "rn-signer-demo";

app.get("/", (req, res) => {
const bundle = req.query.bundle;
const orgId = req.query.orgId;

res.redirect(`${appScheme}://home?bundle=${bundle}&orgId=${orgId}`);
});

app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
89 changes: 22 additions & 67 deletions account-kit/rn-signer/example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,30 @@
/* eslint-disable import/extensions */
import { RNSignerClient } from "@account-kit/react-native-signer";
import type { User } from "@account-kit/signer";
import { useState } from "react";
import { Button, StyleSheet, Text, TextInput, View } from "react-native";
import Config from "react-native-config";
import { createStaticNavigation } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { SafeAreaProvider } from "react-native-safe-area-context";

export default function App() {
const [email, setEmail] = useState<string>("");
const [user, setUser] = useState<User | null>(null);
const [bundle, setBundle] = useState<string>("");
const [orgId, setOrgId] = useState<string>("");
const signer = new RNSignerClient({
connection: { apiKey: Config.API_KEY! },
});
import HomeScreen from "./screens/Home";

// Test the localstorage polyfill
// TODO: remove this before merging
localStorage.setItem("test", "This is from localstorage polyfill");
const linking = {
enabled: "auto" as const /* Automatically generate paths for all screens */,
prefixes: ["rn-signer-demo://"],
};

const test = localStorage.getItem("test");
const RootStack = createNativeStackNavigator({
initialRouteName: "Home",
screens: {
Home: {
screen: HomeScreen,
linking: { path: "home" },
},
},
});

export default function App() {
const Navigation = createStaticNavigation(RootStack);
return (
<View style={styles.container}>
<Text>User: {user ? JSON.stringify(user) : "none"}</Text>
<TextInput
placeholder="email"
onChangeText={setEmail}
value={email}
></TextInput>
<Button
title="Sign in"
onPress={() => {
signer
.initEmailAuth({ email })
.then(({ orgId }) => setOrgId(orgId))
.catch(console.error);
}}
></Button>
<TextInput
placeholder="bundle"
onChangeText={setBundle}
value={bundle}
></TextInput>
<Button
title="Complete auth"
onPress={() => {
signer
.completeAuthWithBundle({
bundle,
authenticatingType: "email",
connectedEventName: "connectedEmail",
orgId,
})
.then(setUser)
.catch(console.error);
}}
></Button>
<Text>{test}</Text>
</View>
<SafeAreaProvider>
<Navigation linking={linking} />
</SafeAreaProvider>
);
}

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
box: {
width: 60,
height: 60,
marginVertical: 20,
},
});
Loading

0 comments on commit 931346f

Please sign in to comment.