Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/expo-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions examples/expo-example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
]
}
Expand Down
8 changes: 4 additions & 4 deletions examples/expo-example/package-lock.json

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

2 changes: 1 addition & 1 deletion examples/expo-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
);
65 changes: 26 additions & 39 deletions examples/expo-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'];
Expand Down Expand Up @@ -304,6 +290,10 @@ function NetworkPickerModal({
}

export default function App() {
const oms = useMemo(
() => new OMSClient({ publishableKey: DEMO_PUBLISHABLE_KEY }),
[]
);
const [networks, setNetworks] = useState<OmsNetwork[]>([]);
const [selectedChainId, setSelectedChainId] = useState('80002');
const [sdkReady, setSdkReady] = useState(false);
Expand Down Expand Up @@ -350,15 +340,15 @@ 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');
setSignatureStatus('Signature status: ready to sign.');
setTransactionStatus('Transaction status: ready to send.');
}
return nextSession;
}, []);
}, [oms]);

const runAction = useCallback(
async (
Expand All @@ -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('');
Expand All @@ -397,7 +387,7 @@ export default function App() {
setTransactionStatus('Transaction status: ready to send.');
appendLog(`Wallet ready: ${address}`);
},
[appendLog]
[appendLog, oms]
);

const finishOidcRedirectSignIn = useCallback(
Expand All @@ -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',
});
Expand Down Expand Up @@ -452,7 +442,7 @@ export default function App() {
handlingRedirectUrlRef.current = null;
}
},
[activateWallet, appendLog, manualWalletSelection, refreshSession]
[activateWallet, appendLog, manualWalletSelection, oms, refreshSession]
);

const selectNetwork = useCallback(
Expand All @@ -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);
Expand All @@ -502,7 +486,7 @@ export default function App() {
return () => {
disposed = true;
};
}, [appendLog, refreshSession, runAction]);
}, [appendLog, oms, refreshSession, runAction]);

useEffect(() => {
if (!sdkReady) return undefined;
Expand Down Expand Up @@ -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}`);
Expand All @@ -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',
});
Expand Down Expand Up @@ -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,
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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.');
Expand All @@ -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,
Expand All @@ -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),
Expand Down
Loading