Skip to content

Commit a83dc24

Browse files
Merge pull request #97 from Web3Auth/feat/expo-example
expo example updates
2 parents 766e163 + 9026d69 commit a83dc24

File tree

16 files changed

+2404
-1729
lines changed

16 files changed

+2404
-1729
lines changed

demo/rn-bare-example/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
"jest": "^29.7.0",
3535
"prettier": "^3.3.2",
3636
"process": "^0.11.10",
37-
"react-native-get-random-values": "^1.11.0",
3837
"react-native-quick-crypto": "^0.7.0",
3938
"react-test-renderer": "18.2.0",
4039
"readable-stream": "^4.5.2",

demo/rn-expo-example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<action android:name="android.intent.action.VIEW"/>
2525
<category android:name="android.intent.category.DEFAULT"/>
2626
<category android:name="android.intent.category.BROWSABLE"/>
27-
<data android:scheme="myapp"/>
27+
<data android:scheme="com.anonymous.rnexpoexample"/>
2828
<data android:scheme="com.anonymous.rnexpoexample"/>
2929
</intent-filter>
3030
</activity>

demo/rn-expo-example/android/app/src/main/res/values/styles.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<item name="android:editTextStyle">@style/ResetEditText</item>
55
<item name="android:editTextBackground">@drawable/rn_edit_text_material</item>
66
<item name="colorPrimary">@color/colorPrimary</item>
7-
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
7+
<item name="android:statusBarColor">#ffffff</item>
88
</style>
99
<style name="ResetEditText" parent="@android:style/Widget.EditText">
1010
<item name="android:padding">0dp</item>

demo/rn-expo-example/app/_layout.tsx

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,54 @@ import * as WebBrowser from "expo-web-browser";
44

55
import { Button, Dimensions, ScrollView, StyleSheet, Text, TextInput, View } from "react-native";
66
import Constants, { AppOwnership } from "expo-constants";
7-
import React, { useEffect, useState } from "react";
8-
import Web3Auth, { ChainNamespace, LOGIN_PROVIDER } from "@web3auth/react-native-sdk";
7+
import { useEffect, useState } from "react";
8+
import Web3Auth, { ChainNamespace, LOGIN_PROVIDER, OpenloginUserInfo } from "@web3auth/react-native-sdk";
99

1010
import RPC from "../ethersRPC"; // for using ethers.js
1111

12+
const chainConfig = {
13+
chainNamespace: ChainNamespace.EIP155,
14+
chainId: "0xaa36a7",
15+
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
16+
// Avoid using public rpcTarget in production.
17+
// Use services like Infura, Quicknode etc
18+
displayName: "Ethereum Sepolia Testnet",
19+
blockExplorerUrl: "https://sepolia.etherscan.io",
20+
ticker: "ETH",
21+
tickerName: "Ethereum",
22+
decimals: 18,
23+
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
24+
};
25+
1226
const resolvedRedirectUrl =
13-
Constants.appOwnership == AppOwnership.Expo || Constants.appOwnership == AppOwnership.Guest
27+
Constants.appOwnership == AppOwnership.Expo
1428
? Linking.createURL("web3auth", {})
1529
: Linking.createURL("web3auth", { scheme: "com.anonymous.rnexpoexample" });
1630

17-
const clientId = "BILxiaDYbvlcwNdeJsyXEUDieKdYPIHfSdvEabzidwYZ3zaGsEN6noiM5u8f-5wuIksJcOn-Ga1LWNqen1eUZbw";
31+
const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ";
1832

1933
export default function App() {
2034
const [key, setKey] = useState("");
21-
const [userInfo, setUserInfo] = useState("");
35+
const [userInfo, setUserInfo] = useState({});
2236
const [console, setConsole] = useState("");
23-
const [web3auth, setWeb3Auth] = useState(null);
24-
const [email, setEmail] = React.useState("[email protected]");
37+
const [web3auth, setWeb3Auth] = useState<Web3Auth | null>(null);
38+
const [email, setEmail] = useState("[email protected]");
2539

2640
useEffect(() => {
2741
const init = async () => {
2842
try {
2943
const auth = new Web3Auth(WebBrowser, SecureStore, {
3044
clientId,
31-
network: "cyan", // or other networks
45+
network: "sapphire_mainnet", // or other networks
46+
redirectUrl: resolvedRedirectUrl,
47+
enableLogging: true,
48+
buildEnv: "testing",
3249
});
3350
setWeb3Auth(auth);
3451
await auth.init();
3552
if (auth?.privKey) {
3653
uiConsole("Re logged in");
37-
setUserInfo(auth.userInfo());
54+
setUserInfo(auth.userInfo() as OpenloginUserInfo);
3855
setKey(auth.privKey);
3956
}
4057
} catch (e) {
@@ -47,16 +64,16 @@ export default function App() {
4764
const login = async () => {
4865
try {
4966
setConsole("Logging in");
50-
await web3auth.login({
67+
await web3auth?.login({
5168
loginProvider: LOGIN_PROVIDER.EMAIL_PASSWORDLESS,
5269
redirectUrl: resolvedRedirectUrl,
5370
extraLoginOptions: {
5471
login_hint: email,
5572
},
5673
});
5774

58-
if (web3auth.privKey) {
59-
setUserInfo(web3auth.userInfo());
75+
if (web3auth?.privKey) {
76+
setUserInfo(web3auth?.userInfo() as OpenloginUserInfo);
6077
setKey(web3auth.privKey);
6178
uiConsole("Logged In");
6279
}
@@ -84,13 +101,7 @@ export default function App() {
84101
}
85102

86103
setConsole("Launch Wallet Services");
87-
await web3auth.launchWalletServices({
88-
chainNamespace: ChainNamespace.EIP155,
89-
decimals: 18,
90-
chainId: "0x1",
91-
rpcTarget: "https://mainnet.infura.io/v3/daeee53504be4cd3a997d4f2718d33e0",
92-
ticker: "ETH",
93-
});
104+
await web3auth.launchWalletServices(chainConfig);
94105
};
95106

96107
const logout = async () => {
@@ -103,7 +114,7 @@ export default function App() {
103114
await web3auth.logout();
104115

105116
if (!web3auth.privKey) {
106-
setUserInfo(undefined);
117+
setUserInfo({});
107118
setKey("");
108119
uiConsole("Logged out");
109120
}
@@ -233,7 +244,7 @@ export default function App() {
233244
uiConsole(res);
234245
};
235246

236-
const uiConsole = (...args) => {
247+
const uiConsole = (...args: unknown[]) => {
237248
setConsole(`${JSON.stringify(args || {}, null, 2)}\n\n\n\n${console}`);
238249
};
239250

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ const getChainId = async () => {
1414
}
1515
};
1616

17-
const getAccounts = async (key) => {
17+
const getAccounts = async (key: string) => {
1818
try {
1919
const wallet = new ethers.Wallet(key);
20-
const address = await wallet.address;
20+
const address = wallet.address;
2121
return address;
2222
} catch (error) {
2323
return error;
2424
}
2525
};
2626

27-
const getBalance = async (key) => {
27+
const getBalance = async (key: string) => {
2828
try {
2929
const ethersProvider = ethers.getDefaultProvider(providerUrl);
3030
const wallet = new ethers.Wallet(key, ethersProvider);
@@ -36,7 +36,7 @@ const getBalance = async (key) => {
3636
}
3737
};
3838

39-
const sendTransaction = async (key) => {
39+
const sendTransaction = async (key: string) => {
4040
try {
4141
const ethersProvider = ethers.getDefaultProvider(providerUrl);
4242
const wallet = new ethers.Wallet(key, ethersProvider);
@@ -60,7 +60,7 @@ const sendTransaction = async (key) => {
6060
}
6161
};
6262

63-
const signMessage = async (key) => {
63+
const signMessage = async (key: string) => {
6464
try {
6565
const ethersProvider = ethers.getDefaultProvider(providerUrl);
6666
const wallet = new ethers.Wallet(key, ethersProvider);

demo/rn-expo-example/globals.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

demo/rn-expo-example/globals.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { install } from "react-native-quick-crypto";
2+
3+
install();
4+
5+
// Needed so that 'stream-http' chooses the right default protocol.
6+
// @ts-ignore
7+
global.location = {
8+
protocol: "file:",
9+
};
10+
// @ts-ignore
11+
global.process.version = "v16.0.0";
12+
if (!global.process.version) {
13+
global.process = require("process");
14+
console.log({ process: global.process });
15+
}
16+
// @ts-ignore
17+
process.browser = true;

demo/rn-expo-example/index.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
import "./globals";
12
import "@ethersproject/shims";
23
import "@expo/metro-runtime";
3-
import "react-native-get-random-values";
4-
import "./globals";
54

65
import { App } from "expo-router/build/qualified-entry";
76
import { renderRootComponent } from "expo-router/build/renderRootComponent";

demo/rn-expo-example/ios/Podfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ target 'rnexpoexample' do
2525
:hermes_enabled => podfile_properties['expo.jsEngine'] == nil || podfile_properties['expo.jsEngine'] == 'hermes',
2626
# An absolute path to your application root.
2727
:app_path => "#{Pod::Config.instance.installation_root}/..",
28-
# Temporarily disable privacy file aggregation by default, until React
29-
# Native 0.74.2 is released with fixes.
30-
:privacy_file_aggregation_enabled => podfile_properties['apple.privacyManifestAggregationEnabled'] == 'true',
28+
:privacy_file_aggregation_enabled => podfile_properties['apple.privacyManifestAggregationEnabled'] != 'false',
3129
)
3230

3331
post_install do |installer|

0 commit comments

Comments
 (0)