Skip to content

Commit

Permalink
docs: update the docs sidebar to treat RN as a first class citizen
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 committed Jan 22, 2025
1 parent 23a0235 commit 4aac063
Show file tree
Hide file tree
Showing 30 changed files with 242 additions and 441 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ account-kit/rn-signer/lib/*
**/ios/generated/*
**/build/*
**/.cxx/*

**/vendor/*
1 change: 1 addition & 0 deletions account-kit/rn-signer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"typecheck": "tsc",
"build": "yarn typecheck",
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
"docs:gen": "node ../../doc-gen/dist/esm/cli.js generate --in ./src/index.ts --out ../../site/pages/reference/account-kit/react-native",
"prepare": "bob build"
},
"keywords": [
Expand Down
5 changes: 2 additions & 3 deletions account-kit/rn-signer/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable import/extensions */
import "./utils/mmkv-localstorage-polyfill";
import { type ConnectionConfig } from "@aa-sdk/core";
import {
BaseSignerClient,
Expand All @@ -14,8 +12,9 @@ import {
type SignupResponse,
type User,
} from "@account-kit/signer";
import NativeTEKStamper from "./NativeTEKStamper";
import { z } from "zod";
import NativeTEKStamper from "./NativeTEKStamper.js";
import "./utils/mmkv-localstorage-polyfill.js";

export const RNSignerClientParamsSchema = z.object({
connection: z.custom<ConnectionConfig>(),
Expand Down
1 change: 1 addition & 0 deletions account-kit/rn-signer/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { RNAlchemySigner } from "./signer.js";
2 changes: 0 additions & 2 deletions account-kit/rn-signer/src/index.tsx

This file was deleted.

26 changes: 23 additions & 3 deletions account-kit/rn-signer/src/signer.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { z } from "zod";
import {
BaseAlchemySigner,
SessionManagerParamsSchema,
} from "@account-kit/signer";
// eslint-disable-next-line import/extensions
import { RNSignerClient, RNSignerClientParamsSchema } from "./client";
import { z } from "zod";
import { RNSignerClient, RNSignerClientParamsSchema } from "./client.js";

const RNAlchemySignerParamsSchema = z
.object({
Expand Down Expand Up @@ -51,6 +50,27 @@ class RNAlchemySignerSingleton extends BaseAlchemySigner<RNSignerClient> {
}
}

/**
* Factory function to create or retrieve a singleton instance of RNAlchemySigner.
*
* @example
* ```ts twoslash
* import { RNAlchemySigner } from "@account-kit/react-native";
*
* const signer = RNAlchemySigner({
* client: {
* apiKey: "YOUR_API_KEY"
* },
* // optional config to override default session manager configs
* sessionConfig: {
* expirationTimeMs: 1000 * 60 * 60 // 60 minutes
* }
* });
* ```
*
* @param {RNAlchemySignerParams} params The parameters required to configure the RNAlchemySigner instance.
* @returns {RNAlchemySignerSingleton} The singleton instance of RNAlchemySigner configured with the provided parameters.
*/
export function RNAlchemySigner(params: RNAlchemySignerParams) {
const instance = RNAlchemySignerSingleton.getInstance(params);

Expand Down
7 changes: 7 additions & 0 deletions site/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DotsIcon } from "../components/icons/DotsIcon";
import { InfraIcon } from "../components/icons/InfraIcon";
import { SmartContractIcon } from "../components/icons/SmartContractIcon";
import { SignerIcon } from "../components/icons/SignerIcon";
import { ReactNativeIcon } from "../components/icons/ReactNativeIcon";

# Get started with Account Kit

Expand Down Expand Up @@ -49,6 +50,12 @@ Account Kit is also published as a set of lower level packages that can be used
utlimate control over your application.

<div className="grid grid-cols-2 gap-8">
<SmallTileRow
icon={<ReactNativeIcon height={20} width={20} />}
title="React Native"
description="Mobile apps with React Native"
href="/react-native/overview"
/>
<SmallTileRow
icon={<DotsIcon />}
title="Other JS Frameworks"
Expand Down
12 changes: 5 additions & 7 deletions site/pages/react-native/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import { ExpoIcon } from "../../components/icons/ExpoIcon";
import { ReactNativeIcon } from "../../components/icons/ReactNativeIcon";
import { TileButton } from "../../components/TileButton";

---

title: Using within React Native applications
description: A guide on integrating Account Kit within a React Native application

---

import { ExpoIcon } from "../../components/icons/ExpoIcon";
import { ReactNativeIcon } from "../../components/icons/ReactNativeIcon";
import { TileButton } from "../../components/TileButton";

# Using within React Native applications

We've built a simple example using expo [here](https://github.com/alchemyplatform/aa-sdk-rn-expo/tree/main). This guide assumes you're using Expo, but the same principles should apply to a bare React Native app as well.
We've built a simple example using expo [here](https://github.com/alchemyplatform/aa-sdk/tree/main/examples/react-native-expo-example). This guide assumes you're using Expo, but the same principles should apply to a bare React Native app as well.

:::warning
The Alchemy Signer is currently in Alpha and only supported on Android devices. To get started using the Alchemy Signer in your React Native app, refer to the [React Native Signer](/react-native/signer/overview) documentation. For 3rd party signer support in React Native, refer to your signer provider's documentation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ For example code on how to use the Signer in your project, please checkout our e

## Create a Signer Instance

```tsx
import { RNAlchemySigner } from "@account-kit/react-native-signer";

const signer = RNAlchemySigner({
client: { connection: { apiKey: API_KEY } },
});
```ts twoslash
// [!include ~/shared/react-native/signer.ts]
```

## Authenticate a User
Expand All @@ -33,7 +29,9 @@ Next, you'll need to authenticate your user before you can use the Signer as an

To send an email magic link to a user, you can use the `signer.authenticate()` method.

```tsx
:::code-group

```ts twoslash [example.ts]
signer
.authenticate({
email: "[email protected]",
Expand All @@ -45,6 +43,12 @@ signer
});
```

```ts twoslash [signer.ts] filename="signer.ts"
// [!include ~/shared/react-native/signer.ts]
```

:::

### Authenticate User via Deep Link

When a user clicks on the magic link in their email, it should deep link to your app if this has been setup correctly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,8 @@ For example code on how to use the Signer in your project, please checkout our e

## Create a Signer Instance

```tsx
import { RNAlchemySigner } from "@account-kit/react-native-signer";

const signer = RNAlchemySigner({
client: { connection: { apiKey: API_KEY } },
});
```ts twoslash
// [!include ~/shared/react-native/signer.ts]
```

## Authenticate a User
Expand All @@ -33,7 +29,9 @@ Next, you'll need to authenticate your user before you can use the Signer as an

To send an OTP to a user's email, use the `signer.authenticate()` method with the `emailMode` set to `otp`.

```tsx
:::code-group

```ts twoslash [example.ts]
signer
.authenticate({
email: "[email protected]",
Expand All @@ -45,6 +43,12 @@ signer
});
```

```ts twoslash [signer.ts] filename="signer.ts"
// [!include ~/shared/react-native/signer.ts]
```

:::

### Prompt the User to enter the One-Time Password to complete authentication

The user will receive an email with a one-time password (OTP) to enter into your app.
Expand Down
10 changes: 5 additions & 5 deletions site/pages/react-native/signer/setup-guide.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ description: Setup the React Native Signer Package in your React Native Project
---

:::warning
**CAUTION:** The Alchemy Signer is currently in Alpha and only supported on Android devices.
**CAUTION:** The Alchemy Signer is currently in Alpha.
:::

For more information on what a Signer is, refer to the [concepts](/concepts/smart-account-signer) page.

# Setting up your project to use the React Native Signer

Setting up the React Native Signer is similar to setting up the [React Signer](/signer/quickstart) with a few extra steps.
# React Native Signer setup guide

:::info
Only the Email Auth method is supported for the React Native Signer at this time.
The React Native Signer package is only supported on React Native's new architecture, and requires your project to be on React Native version 0.76 or newer.
:::

Setting up the React Native Signer is similar to setting up the [React Signer](/signer/quickstart) with a few extra steps.

1. Get your **API key** by creating a new app in your [Alchemy Dashboard](https://dashboard.alchemy.com/apps)
:::warning
Make sure **Ethereum** is enabled for your app under the Networks tab
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions site/scripts/prebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const referencePackages = [
"@account-kit/react",
"@account-kit/signer",
"@account-kit/smart-contracts",
"@account-kit/react-native",
"@aa-sdk/core",
"@aa-sdk/ethers",
];
Expand Down
10 changes: 10 additions & 0 deletions site/shared/react-native/signer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { RNAlchemySigner } from "@account-kit/react-native-signer";

export const signer = RNAlchemySigner({
client: { connection: { apiKey: "API_KEY" } },
// optional param to override session settings
sessionConfig: {
// sets the expiration to 60 minutes
expirationTimeMs: 1000 * 60 * 60,
},
});
4 changes: 2 additions & 2 deletions site/sidebar/index.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions site/sidebar/react-native.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions site/sidebar/react-native/authenticating-users.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions site/sidebar/react-native/getting-started.ts

This file was deleted.

9 changes: 0 additions & 9 deletions site/sidebar/react-native/index.ts

This file was deleted.

Loading

0 comments on commit 4aac063

Please sign in to comment.