diff --git a/examples/expo-example/README.md b/examples/expo-example/README.md index 863a26f..e396adf 100644 --- a/examples/expo-example/README.md +++ b/examples/expo-example/README.md @@ -8,7 +8,7 @@ sending. It uses `expo-web-browser` for redirect auth and depends on the published npm package: ```json -"@0xsequence/oms-react-native-sdk": "0.1.0-alpha.2" +"@0xsequence/oms-react-native-sdk": "0.1.0-alpha.3" ``` This example is intentionally excluded from the root Yarn workspace. It is not diff --git a/examples/expo-example/app.json b/examples/expo-example/app.json index 6b7e2ed..f5cb36b 100644 --- a/examples/expo-example/app.json +++ b/examples/expo-example/app.json @@ -19,9 +19,16 @@ "expo-build-properties", { "android": { + "kotlinVersion": "2.3.20", "minSdkVersion": 26 } } + ], + [ + "./plugins/with-android-kotlin-gradle-plugin-version", + { + "version": "2.3.20" + } ] ] } diff --git a/examples/expo-example/package-lock.json b/examples/expo-example/package-lock.json index 588b11e..500d667 100644 --- a/examples/expo-example/package-lock.json +++ b/examples/expo-example/package-lock.json @@ -8,7 +8,7 @@ "name": "oms-client-react-native-sdk-expo-example", "version": "0.0.1", "dependencies": { - "@0xsequence/oms-react-native-sdk": "0.1.0-alpha.2", + "@0xsequence/oms-react-native-sdk": "0.1.0-alpha.3", "expo": "~56.0.8", "expo-build-properties": "~56.0.17", "expo-dev-client": "~56.0.19", @@ -26,9 +26,9 @@ } }, "node_modules/@0xsequence/oms-react-native-sdk": { - "version": "0.1.0-alpha.2", - "resolved": "https://registry.npmjs.org/@0xsequence/oms-react-native-sdk/-/oms-react-native-sdk-0.1.0-alpha.2.tgz", - "integrity": "sha512-OWX/ibaIEd2D9NmINnaqxkIH9uwZjpVHRKAbEcDQvTpxvi1tPcRD6KwvSEMl+6cwB7z+qXxqgb24Pyxfl33sww==", + "version": "0.1.0-alpha.3", + "resolved": "https://registry.npmjs.org/@0xsequence/oms-react-native-sdk/-/oms-react-native-sdk-0.1.0-alpha.3.tgz", + "integrity": "sha512-4HsfsMT67BHbhL5ERA7gc4GW24PmoTFuZvMxDKsizH1k3jACt4thdyveNwBC1f/Qyc4AHtdA5ARznYrD07RCUg==", "license": "MIT", "workspaces": [ "examples/*", diff --git a/examples/expo-example/package.json b/examples/expo-example/package.json index 40c13f4..a568673 100644 --- a/examples/expo-example/package.json +++ b/examples/expo-example/package.json @@ -12,7 +12,7 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@0xsequence/oms-react-native-sdk": "0.1.0-alpha.2", + "@0xsequence/oms-react-native-sdk": "0.1.0-alpha.3", "expo": "~56.0.8", "expo-build-properties": "~56.0.17", "expo-dev-client": "~56.0.19", diff --git a/examples/expo-example/plugins/with-android-kotlin-gradle-plugin-version.js b/examples/expo-example/plugins/with-android-kotlin-gradle-plugin-version.js new file mode 100644 index 0000000..5b43c9f --- /dev/null +++ b/examples/expo-example/plugins/with-android-kotlin-gradle-plugin-version.js @@ -0,0 +1,24 @@ +const { + createRunOncePlugin, + withProjectBuildGradle, +} = require('expo/config-plugins'); + +const DEFAULT_KOTLIN_VERSION = '2.3.20'; + +function withAndroidKotlinGradlePluginVersion(config, props = {}) { + const kotlinVersion = props.version ?? DEFAULT_KOTLIN_VERSION; + + return withProjectBuildGradle(config, (nextConfig) => { + nextConfig.modResults.contents = nextConfig.modResults.contents.replace( + /classpath\(['"]org\.jetbrains\.kotlin:kotlin-gradle-plugin(?::[^'"]+)?['"]\)/, + `classpath('org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}')` + ); + return nextConfig; + }); +} + +module.exports = createRunOncePlugin( + withAndroidKotlinGradlePluginVersion, + 'with-android-kotlin-gradle-plugin-version', + '1.0.0' +); diff --git a/examples/expo-example/src/App.tsx b/examples/expo-example/src/App.tsx index 82bc8d8..6cf5c8c 100644 --- a/examples/expo-example/src/App.tsx +++ b/examples/expo-example/src/App.tsx @@ -19,18 +19,8 @@ import { View, } from 'react-native'; import { - completeEmailAuth, - configure, - getSupportedNetworks, - getSession, - sendTransaction, - handleOidcRedirectCallback, + OMSClient, OidcProviders, - signMessage, - signOut, - startEmailAuth, - startOidcRedirectAuth, - verifyMessageSignature, type OmsClientSessionState, type OmsNetwork, type OmsPendingWalletSelection, @@ -40,13 +30,9 @@ import { WebBrowser.maybeCompleteAuthSession(); -const DEMO_PUBLISHABLE_KEY = 'AQAAAAAAAAK2JvvZhWqZ51riasWBftkrVXE'; -const DEMO_PROJECT_ID = 'proj_014kg56dc0a75'; +const DEMO_PUBLISHABLE_KEY = + 'pk_dev_sdbx_01kqa06hyyetj_01kv5ceg4xefattzmm9fyx04ev'; const DEMO_OIDC_REDIRECT_URI = 'omsclientrndemo://auth/callback'; -const DEMO_ENVIRONMENT = { - apiRpcUrl: 'https://dev-api.sequence.app/rpc/API', - indexerUrlTemplate: 'https://dev-{value}-indexer.sequence.app/rpc/Indexer/', -}; const DEFAULT_TRANSACTION_TO = '0xE5E8B483FfC05967FcFed58cc98D053265af6D99'; const PREFERRED_NETWORK_ORDER = ['80002', '137']; @@ -304,6 +290,10 @@ function NetworkPickerModal({ } export default function App() { + const oms = useMemo( + () => new OMSClient({ publishableKey: DEMO_PUBLISHABLE_KEY }), + [] + ); const [networks, setNetworks] = useState([]); const [selectedChainId, setSelectedChainId] = useState('80002'); const [sdkReady, setSdkReady] = useState(false); @@ -350,7 +340,7 @@ export default function App() { }, []); const refreshSession = useCallback(async () => { - const nextSession = await getSession(); + const nextSession = await oms.wallet.getSession(); setSession(nextSession); if (nextSession.walletAddress) { setAuthStatus('Restored persisted wallet session'); @@ -358,7 +348,7 @@ export default function App() { setTransactionStatus('Transaction status: ready to send.'); } return nextSession; - }, []); + }, [oms]); const runAction = useCallback( async ( @@ -382,7 +372,7 @@ export default function App() { const activateWallet = useCallback( async (result: OmsWalletActivationResult) => { - const nextSession = await getSession(); + const nextSession = await oms.wallet.getSession(); const address = nextSession.walletAddress ?? result.walletAddress; setPendingWalletSelection(null); setCode(''); @@ -397,7 +387,7 @@ export default function App() { setTransactionStatus('Transaction status: ready to send.'); appendLog(`Wallet ready: ${address}`); }, - [appendLog] + [appendLog, oms] ); const finishOidcRedirectSignIn = useCallback( @@ -412,7 +402,7 @@ export default function App() { handlingRedirectUrlRef.current = callbackUrl; try { setAuthStatus('Completing Google redirect sign-in...'); - const result = await handleOidcRedirectCallback({ + const result = await oms.wallet.handleOidcRedirectCallback({ callbackUrl, walletSelection: manualWalletSelection ? 'manual' : 'automatic', }); @@ -452,7 +442,7 @@ export default function App() { handlingRedirectUrlRef.current = null; } }, - [activateWallet, appendLog, manualWalletSelection, refreshSession] + [activateWallet, appendLog, manualWalletSelection, oms, refreshSession] ); const selectNetwork = useCallback( @@ -476,13 +466,7 @@ export default function App() { async function bootstrap() { await runAction('Initializing SDK', async () => { - await configure({ - publishableKey: DEMO_PUBLISHABLE_KEY, - projectId: DEMO_PROJECT_ID, - environment: DEMO_ENVIRONMENT, - }); - - const supportedNetworks = sortNetworks(await getSupportedNetworks()); + const supportedNetworks = sortNetworks(oms.supportedNetworks); if (disposed) return; setNetworks(supportedNetworks); @@ -502,7 +486,7 @@ export default function App() { return () => { disposed = true; }; - }, [appendLog, refreshSession, runAction]); + }, [appendLog, oms, refreshSession, runAction]); useEffect(() => { if (!sdkReady) return undefined; @@ -553,7 +537,7 @@ export default function App() { const normalizedEmail = requireText(email, 'Email'); setAuthStatus('Requesting email code...'); setPendingWalletSelection(null); - await startEmailAuth(normalizedEmail); + await oms.wallet.startEmailAuth(normalizedEmail); setEmail(''); setAuthStage('code'); setAuthStatus(`Code requested for ${normalizedEmail}`); @@ -569,7 +553,7 @@ export default function App() { 'Confirm code and resolve wallet', async () => { setAuthStatus('Confirming code and resolving wallet...'); - const authResult = await completeEmailAuth({ + const authResult = await oms.wallet.completeEmailAuth({ code: requireText(code, 'Verification code'), walletSelection: manualWalletSelection ? 'manual' : 'automatic', }); @@ -600,7 +584,7 @@ export default function App() { async () => { setPendingWalletSelection(null); setAuthStatus('Opening Google redirect sign-in...'); - const started = await startOidcRedirectAuth({ + const started = await oms.wallet.startOidcRedirectAuth({ provider: OidcProviders.google(), redirectUri: DEMO_OIDC_REDIRECT_URI, }); @@ -629,7 +613,7 @@ export default function App() { const cancelCodeStep = () => { runAction('Cancel email code step', async () => { - await signOut(); + await oms.wallet.signOut(); setSession(SIGNED_OUT_SESSION); setCode(''); setPendingWalletSelection(null); @@ -670,7 +654,7 @@ export default function App() { const logout = () => { runAction('Logout', async () => { - await signOut(); + await oms.wallet.signOut(); setSession(SIGNED_OUT_SESSION); setAuthStage('email'); setPendingWalletSelection(null); @@ -691,7 +675,10 @@ export default function App() { const network = requireNetwork(selectedNetwork); const nextMessage = requireText(message, 'Message'); setSignatureStatus('Signature status: signing in progress...'); - const signature = await signMessage(network.chainId, nextMessage); + const signature = await oms.wallet.signMessage( + network.chainId, + nextMessage + ); setLastSignedMessage(nextMessage); setLastSignature(signature); setSignatureStatus('Signature status: signed. Ready to verify.'); @@ -711,7 +698,7 @@ export default function App() { const signedMessage = requireText(lastSignedMessage, 'Signed message'); const signature = requireText(lastSignature, 'Signature'); setSignatureStatus('Signature status: verification in progress...'); - const isValid = await verifyMessageSignature({ + const isValid = await oms.wallet.verifyMessageSignature({ chainId: network.chainId, message: signedMessage, signature, @@ -735,7 +722,7 @@ export default function App() { async () => { const network = requireNetwork(selectedNetwork); setTransactionStatus('Transaction status: sending in progress...'); - const txResult = await sendTransaction({ + const txResult = await oms.wallet.sendTransaction({ chainId: network.chainId, to: requireText(transactionTo, 'Transaction destination'), value: decimalToBaseUnits(transactionValue, 18),