Skip to content

Commit 870a8bb

Browse files
authored
fix: Privy ("Already used" error) (#1599)
1 parent fbbd8ef commit 870a8bb

17 files changed

+207
-1116
lines changed

.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ build-*.apk
2525
expo-env.d.ts
2626

2727
# iOS
28-
ios/Converse.xcworkspace/xcshareddata/swiftpm/Package.resolved
28+
/ios/
2929
*.jks
3030
*.p8
3131
*.p12
@@ -36,9 +36,6 @@ ios/Converse.xcworkspace/xcshareddata/swiftpm/Package.resolved
3636
# Android
3737
/android/
3838

39-
# iOS
40-
/ios/
41-
4239
# System files
4340
.DS_Store
4441
*.log

App.tsx

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
// Keep this at the top
2-
import "./polyfills";
3-
4-
import * as Privy from "@privy-io/expo";
1+
import { PrivyProvider } from "@privy-io/expo";
52

63
// This is a requirement for Privy to work, does not make any sense
74
// To test run yarn start --no-dev --minify
8-
const PrivyProvider = Privy.PrivyProvider;
95

6+
import { setupStreamingSubscriptions } from "@/features/streams/streams";
107
import { configure as configureCoinbase } from "@coinbase/wallet-mobile-sdk";
118
import DebugButton from "@components/DebugButton";
129
import { Snackbars } from "@components/Snackbar/Snackbars";
@@ -40,7 +37,6 @@ import {
4037
configureReanimatedLogger,
4138
} from "react-native-reanimated";
4239
import { ThirdwebProvider } from "thirdweb/react";
43-
import { base } from "viem/chains";
4440
import { config } from "./config";
4541
import {
4642
TEMPORARY_ACCOUNT_NAME,
@@ -49,11 +45,9 @@ import {
4945
import { setAuthStatus } from "./data/store/authStore";
5046
import Main from "./screens/Main";
5147
import { registerBackgroundFetchTask } from "./utils/background";
52-
import { privySecureStorage } from "./utils/keychain/helpers";
5348
import { initSentry } from "./utils/sentry";
5449
import { saveApiURI } from "./utils/sharedData";
5550
import { preventSplashScreenAutoHide } from "./utils/splash/splash";
56-
import { setupStreamingSubscriptions } from "@/features/streams/streams";
5751

5852
preventSplashScreenAutoHide();
5953

@@ -176,10 +170,11 @@ export default function AppWithProviders() {
176170
return (
177171
<QueryClientProvider client={queryClient}>
178172
<PrivyProvider
179-
appId={config.privy.appId}
180-
clientId={config.privy.clientId}
181-
storage={privySecureStorage}
182-
supportedChains={[base]}
173+
appId="cloh5bn1p00q4l50gcg0g1mix"
174+
clientId="client-WY2eFe3hjqkyEyrGWiZoJUqsihgrJieWcXjcKN4f3mwXM"
175+
176+
// storage={privySecureStorage}
177+
// supportedChains={[base]}
183178
>
184179
<SmartWalletsProvider>
185180
<ThirdwebProvider>

app.config.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,18 @@ export default (): ExpoConfig => {
116116
ios: {
117117
bundleIdentifier: config.ios.bundleIdentifier,
118118
supportsTablet: true,
119+
associatedDomains: config.ios.associatedDomains,
120+
googleServicesFile: config.ios.googleServicesFile,
119121
config: {
120122
usesNonExemptEncryption: false,
121123
},
122-
associatedDomains: config.ios.associatedDomains,
123-
googleServicesFile: config.ios.googleServicesFile,
124+
entitlements: {
125+
// App check stuff
126+
"com.apple.developer.devicecheck.appattest-environment": "production",
127+
},
124128
infoPlist: {
125129
LSApplicationQueriesSchemes: [
126130
"cbwallet",
127-
"ledgerlive",
128131
"rainbow",
129132
"metamask",
130133
"trust",
@@ -133,6 +136,10 @@ export default (): ExpoConfig => {
133136
"exodus",
134137
"oneinch",
135138
],
139+
NSAppTransportSecurity: {
140+
NSAllowsArbitraryLoads: false, // Not sure why
141+
NSAllowsLocalNetworking: true, // Not sure why
142+
},
136143
},
137144
},
138145
android: {
@@ -205,7 +212,14 @@ export default (): ExpoConfig => {
205212
},
206213
plugins: [
207214
["expo-notifications"],
208-
["expo-local-authentication"],
215+
["expo-secure-store"],
216+
[
217+
"expo-local-authentication",
218+
{
219+
faceIDPermission:
220+
"We need this to use biometrics to secure your data.",
221+
},
222+
],
209223
[
210224
"expo-build-properties",
211225
{
@@ -216,6 +230,7 @@ export default (): ExpoConfig => {
216230
// you may set `use_modular_headers!` globally in your Podfile,
217231
// or specify `:modular_headers => true` for particular dependencies"
218232
useFrameworks: "static",
233+
deploymentTarget: "17.5",
219234
},
220235
android: {
221236
compileSdkVersion: 35,
@@ -305,7 +320,6 @@ export default (): ExpoConfig => {
305320
"We need this so that you can take photos to share.",
306321
},
307322
],
308-
"expo-secure-store",
309323
[
310324
"expo-splash-screen",
311325
{
@@ -327,6 +341,7 @@ export default (): ExpoConfig => {
327341
],
328342
["@react-native-firebase/app"],
329343
["@react-native-firebase/app-check"],
344+
"./scripts/android/build/android-deps-expo-plugin.js",
330345
],
331346
};
332347
};

features/onboarding/Privy/usePrivySmartWalletConnection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ export function usePrivySmartWalletConnection(args: {
8585
return smartAccount.signMessage({ message });
8686
},
8787
};
88-
console.log("1");
88+
8989
await initXmtpClientFromViemAccount({
9090
account: viemAccount,
9191
});
92-
console.log("2");
92+
9393
onStatusChange("Xmtp initialized");
9494
onConnectionDone();
9595
} catch (error) {

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./wdyr";
2-
import "react-native-gesture-handler";
3-
import "react-native-url-polyfill/auto";
2+
import "./polyfills";
3+
44
import { registerRootComponent } from "expo";
55

66
import App from "./App";

ios/Podfile.properties.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"expo.jsEngine": "hermes",
33
"EX_DEV_CLIENT_NETWORK_INSPECTOR": "true",
44
"newArchEnabled": "false",
5+
"ios.deploymentTarget": "17.5",
56
"ios.useFrameworks": "static",
67
"apple.extraPods": "[]",
78
"apple.ccacheEnabled": "false",

package.json

+3-6
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,15 @@
55
"scripts": {
66
"start": "expo start",
77
"android": "expo run:android",
8+
"android:clean": "expo prebuild --clean -p android && yarn android",
89
"android:build:dev": "npx eas-cli build -p android --profile development --local",
910
"android:reverse": "adb reverse tcp:8081 tcp:8081 && adb reverse tcp:9875 tcp:9875",
1011
"android:sendApk": "./scripts/android/send-apk.sh",
1112
"ios": "expo run:ios",
12-
"ios:clean": "yarn ios --no-build-cache",
13-
"prebuild:ios:clean": "expo prebuild --platform ios --clean",
13+
"ios:clean": "expo prebuild --clean -p ios && yarn ios",
1414
"env:pull:dev": "npx eas-cli env:pull --environment=development",
1515
"env:pull:preview": "npx eas-cli env:pull --environment=preview",
1616
"env:pull:prod": "npx eas-cli env:pull --environment=production",
17-
"clean": "./scripts/react-native-clean-build.sh",
1817
"lint": "eslint --max-warnings 2500",
1918
"lint:errors": "eslint --quiet",
2019
"typecheck": "echo \"➜ Typechecking project...\" && tsc --noEmit",
@@ -40,9 +39,8 @@
4039
"@noble/secp256k1": "^1.5.2",
4140
"@open-frames/proxy-types": "^0.2.3",
4241
"@peculiar/webcrypto": "^1.4.1",
43-
"@privy-io/expo": "^0.39.0",
42+
"@privy-io/expo": "^0.45.0",
4443
"@privy-io/expo-native-extensions": "^0.0.3",
45-
"@privy-io/react-auth": "^1.65.1",
4644
"@react-native-async-storage/async-storage": "1.23.1",
4745
"@react-native-clipboard/clipboard": "^1.14.1",
4846
"@react-native-community/netinfo": "11.4.1",
@@ -98,7 +96,6 @@
9896
"expo-build-properties": "~0.13.1",
9997
"expo-clipboard": "~7.0.0",
10098
"expo-constants": "~17.0.4",
101-
"expo-contacts": "~14.0.2",
10299
"expo-crypto": "~14.0.2",
103100
"expo-crypto-polyfills": "^1.1.0",
104101
"expo-dev-client": "~5.0.4",

polyfills.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
11
// IMPORTANT: DO NOT CHANGE THE ORDER OF THESE IMPORTS
2-
// These imports must be in this specific order for polyfills to work correctly
32
import "@walletconnect/react-native-compat";
4-
import "react-native-get-random-values"; // Privy requires this
5-
import "@ethersproject/shims"; // Privy requires this
63

7-
import "@azure/core-asynciterator-polyfill";
8-
9-
// For now using all the polyfills. Need to dig which one we'll really need.
10-
import "react-native-polyfill-globals";
4+
// Privy require those in this order https://github.com/privy-io/expo-starter/blob/main/entrypoint.js
5+
import "fast-text-encoding";
6+
import "react-native-get-random-values";
7+
import "@ethersproject/shims";
118

9+
import "@azure/core-asynciterator-polyfill";
10+
import "react-native-polyfill-globals/auto";
1211
import { Crypto as WebCrypto } from "@peculiar/webcrypto";
1312
import "@stardazed/streams-polyfill";
1413

14+
import "react-native-gesture-handler";
15+
import "react-native-url-polyfill/auto";
16+
1517
// Necessary for @peculiar/webcrypto.
1618
if (!global.Buffer) {
1719
global.Buffer = require("safe-buffer").Buffer;
1820
}
21+
1922
if (!global.crypto.subtle) {
2023
// Only polyfill SubtleCrypto as we prefer `react-native-get-random-values` for getRandomValues.
2124
const webCrypto = new WebCrypto();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* This work was done by Noe.
3+
* It handles some conflicting dependencies manually.
4+
* It seems to be needed for now for Android build to work with eas.
5+
* We might be able to remove it once we will clean up our dependencies?
6+
* Maybe not since it's used by many crypto libs
7+
* https://github.com/expo/expo/issues/29026#issuecomment-2173524698
8+
*/
9+
const {
10+
createRunOncePlugin,
11+
withAppBuildGradle,
12+
} = require("@expo/config-plugins");
13+
const {
14+
mergeContents,
15+
} = require("@expo/config-plugins/build/utils/generateCode");
16+
17+
const withFixedConverseAndroidDependencies = (config) => {
18+
return withAppBuildGradle(config, (config) => {
19+
if (config.modResults.contents) {
20+
config.modResults.contents = setBouncyCastleVersion(
21+
config.modResults.contents
22+
);
23+
}
24+
return config;
25+
});
26+
};
27+
28+
const TAG = "converse-android-dependencies-fix";
29+
30+
const setBouncyCastleVersion = (src) => {
31+
const configurationFix = `
32+
configurations.all {
33+
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
34+
if (details.requested.name == 'bcprov-jdk15on') {
35+
details.useTarget group: details.requested.group, name: 'bcprov-jdk15to18', version: '1.78.1'
36+
}
37+
if (details.requested.name == 'lifecycle-viewmodel-ktx') {
38+
details.useTarget group: details.requested.group, name: 'lifecycle-viewmodel-ktx', version: '2.5.0'
39+
}
40+
}
41+
}
42+
`;
43+
44+
const mergeResults = mergeContents({
45+
tag: TAG,
46+
src: src,
47+
newSrc: configurationFix,
48+
anchor: /android {/gm,
49+
offset: 1,
50+
comment: `// `,
51+
});
52+
53+
return mergeResults.contents;
54+
};
55+
56+
module.exports = createRunOncePlugin(
57+
withFixedConverseAndroidDependencies,
58+
"withFixedConverseAndroidDependencies",
59+
"1.0.0"
60+
);

scripts/react-native-clean-build.sh

-44
This file was deleted.

0 commit comments

Comments
 (0)