Skip to content

Commit

Permalink
feat: test
Browse files Browse the repository at this point in the history
  • Loading branch information
limichange committed Jan 25, 2025
1 parent e7ec3f9 commit f8eccdb
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 36 deletions.
2 changes: 1 addition & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@onekeyhq/components": "*",
"@onekeyhq/kit": "*",
"@onekeyhq/shared": "*",
"@privy-io/expo": "0.40.0",
"@privy-io/expo": "0.42.0",
"@privy-io/expo-native-extensions": "^0.0.3",
"@react-native-async-storage/async-storage": "1.22.0",
"@react-native-community/netinfo": "^11.4.1",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@polkadot/extension-inject": "0.46.6",
"@polkadot/types": "11.3.1",
"@polkadot/util-crypto": "12.6.2",
"@privy-io/react-auth": "2.0.4",
"@privy-io/react-auth": "1.98.4",
"@revenuecat/purchases-js": "^0.15.1",
"@sentry/browser": "8.42.0",
"@sentry/core": "8.42.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ function PrivyAuthSyncToAtom() {
}

export function PrivyProvider({ children }: { children: React.ReactNode }) {
const appId = process.env.PRIVY_APP_ID ?? '';
const clientId = process.env.PRIVY_MOBILE_CLIENT_ID ?? '';
const appId = process.env.PRIVY_APP_ID ?? 'cm5599w1609v7kfpecfmser60';
const clientId =
process.env.PRIVY_MOBILE_CLIENT_ID ??
'client-WY5fBvyK4K8iTegm8s91XNttaKsDN9mJeTJUu1FXxckKp';
if (!appId) {
throw new Error('PRIVY_APP_ID is not set');
}
if (!clientId) {
throw new Error('PRIVY_MOBILE_CLIENT_ID is not set');
}
// throw new Error('PRIVY_MOBILE_CLIENT_ID is not set');

return (
<PrivyProviderBase appId={appId} clientId={clientId}>
Expand Down
9 changes: 7 additions & 2 deletions packages/kit/src/views/Prime/components/PrivyProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ function PrivyAuthSyncToAtom() {
}

export function PrivyProvider({ children }: { children: React.ReactNode }) {
const appId = process.env.PRIVY_APP_ID ?? '';
console.log('nnnn', process.env);
const appId = process.env.PRIVY_APP_ID ?? 'cm5599w1609v7kfpecfmser60';
const clientId =
process.env.PRIVY_MOBILE_CLIENT_ID ??
'client-WY5fBvyK4K8iTegm8s91XNttaKsDN9mJeTJUu1FXxckKp';
if (!appId) {
throw new Error('PRIVY_APP_ID is not set');
}
if (!clientId) {
throw new Error('PRIVY_MOBILE_CLIENT_ID is not set');
}

// TODO: ext error
// Embedded wallet is only available over HTTPS
Expand Down
42 changes: 42 additions & 0 deletions packages/kit/src/views/Prime/hooks/PrimeSignupTest.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useState } from 'react';

import { useLoginWithEmail } from '@privy-io/expo';

import { Button, Input, OTPInput, Toast, YStack } from '@onekeyhq/components';

export function PrimeSignupTest() {
const [email, setEmail] = useState('[email protected]');
const { sendCode, loginWithCode, state } = useLoginWithEmail({
onSendCodeSuccess() {
Toast.message({
title: 'onSendCodeSuccess',
});
},
onLoginSuccess(user, isNewUser) {
Toast.success({
title: 'onLoginSuccess',
message: `user${JSON.stringify(user, null, 2)}`,
});
},
onError(error) {
console.log('error', error);
// show a toast, update form errors, etc...
},
});
const [codeEmail, setCodeEmail] = useState('');
return (
<YStack>
<Input
value={email}
onChangeText={setEmail}
placeholder="Email"
inputMode="email"
/>
<Button onPress={() => sendCode({ email })}>Send Code</Button>
<OTPInput value={codeEmail} onTextChange={setCodeEmail} />
<Button onPress={() => loginWithCode({ code: codeEmail, email })}>
Login
</Button>
</YStack>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useLoginWithEmail, usePrivy } from '@privy-io/expo';

import type { IUsePrivyUniversalV2 } from './usePrivyUniversalV2Types';
import { Toast } from '@onekeyhq/components';

export function usePrivyUniversalV2(): IUsePrivyUniversalV2 {
const { logout, isReady, getAccessToken, user } = usePrivy();
Expand All @@ -10,6 +11,11 @@ export function usePrivyUniversalV2(): IUsePrivyUniversalV2 {
useLoginWithEmail: (args) => {
const { onComplete, onError } = args || {};
const { sendCode, loginWithCode, state } = useLoginWithEmail({
onSendCodeSuccess: () => {
Toast.success({
title: 'send code',
});
},
onLoginSuccess: () => {
onComplete?.();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ export default function PrimeDashboard() {

if (!user?.isLoggedIn) {
await loginWithEmail();
}

if (platformEnv.isNative) {
} else if (platformEnv.isNative) {
ActionList.show({
title: 'Purchase',
onClose: () => {},
Expand Down Expand Up @@ -304,6 +302,8 @@ export default function PrimeDashboard() {
PaywallPackages
</Button>
</XStack>

{/* <PrimeSignupTest /> */}
</Page.Body>

<Page.Footer
Expand Down
Loading

0 comments on commit f8eccdb

Please sign in to comment.