-
Couldn't load subscription status.
- Fork 29
feat: unifies api for both otp signers #1313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@crossmint/client-sdk-react-native-ui": minor | ||
| "@crossmint/client-sdk-react-ui": minor | ||
| "@crossmint/wallets-sdk": minor | ||
| --- | ||
|
|
||
| Unifies callback calls for otp signers |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import { | ||
| useCrossmintAuth, | ||
| useWallet, | ||
| useWalletEmailSigner, | ||
| useWalletOtpSigner, | ||
| useCrossmint, | ||
| type Balances, | ||
| StellarWallet, | ||
| } from "@crossmint/client-sdk-react-native-ui"; | ||
| import { useEffect, useMemo, useState } from "react"; | ||
| import { ActivityIndicator, Button, Text, View, TextInput, StyleSheet, ScrollView, Alert } from "react-native"; | ||
|
|
@@ -15,7 +16,7 @@ export default function Index() { | |
| const { experimental_customAuth } = useCrossmint(); | ||
| const loggedInUserEmail = experimental_customAuth?.email ?? null; | ||
| const { wallet, getOrCreateWallet, status: walletStatus } = useWallet(); | ||
| const { needsAuth, sendEmailWithOtp, verifyOtp } = useWalletEmailSigner(); | ||
| const { needsAuth, sendOtp, verifyOtp } = useWalletOtpSigner(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may be wrong but iirc its an anti pattern to have read and write properties in the same hook There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where does that come from? The most used hook in react has both a read and write state:
|
||
| const walletAddress = useMemo(() => wallet?.address, [wallet]); | ||
| const url = Linking.useURL(); | ||
|
|
||
|
|
@@ -80,7 +81,8 @@ export default function Index() { | |
| } | ||
| setIsLoading(true); | ||
| try { | ||
| await getOrCreateWallet({ chain: "stellar", signer: { type: "email" } }); | ||
| // await getOrCreateWallet({ chain: "stellar", signer: { type: "email" } }); | ||
| await getOrCreateWallet({ chain: "stellar", signer: { type: "phone", phone: "+13472008361" } }); | ||
| } catch (error) { | ||
| console.error("Error initializing wallet:", error); | ||
| } finally { | ||
|
|
@@ -113,7 +115,7 @@ export default function Index() { | |
| return; | ||
| } | ||
| setIsInOtpFlow(true); | ||
| await handleAction(sendEmailWithOtp); | ||
| await handleAction(sendOtp); | ||
| }; | ||
|
|
||
| const handleVerifyOtpInput = async () => { | ||
|
|
@@ -135,7 +137,19 @@ export default function Index() { | |
| } | ||
| setIsLoading(true); | ||
| try { | ||
| const tx = await wallet.send(recipientAddress, "usdc", amount); | ||
| const transaction = { | ||
| type: "contract-call", | ||
| contractId: "CDMUQY2ZHWIGXSTHPHX53ACR76OLXCCAAKQWQWUS2JNAH6SZEXMRU6R2", | ||
| method: "transfer", | ||
| args: { | ||
| from: wallet.address, | ||
| to: recipientAddress, | ||
| amount, | ||
| }, | ||
| }; | ||
| const stellarWallet = StellarWallet.from(wallet); | ||
| const tx = await stellarWallet.sendTransaction(transaction); | ||
| // const tx = await wallet.send(recipientAddress, "usdc", amount); | ||
| console.log(`Sent ${amount} USDC to ${recipientAddress}. Tx Link: ${tx.explorerLink}`); | ||
| setTxLink(tx.explorerLink); | ||
| setRecipientAddress(""); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| export { useCrossmint, useWallet } from "@crossmint/client-sdk-react-base"; | ||
| export * from "./useCrossmintAuth"; | ||
| export * from "./useWalletEmailSigner"; | ||
| export * from "./useWalletOtpSigner"; |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { CrossmintWalletEmailSignerContext } from "@/providers/CrossmintWalletProvider"; | ||
| import { useContext } from "react"; | ||
|
|
||
| export type OtpSignerFunctions = { | ||
| needsAuth: boolean; | ||
| sendOtp: () => Promise<void>; | ||
| verifyOtp: (otp: string) => Promise<void>; | ||
| reject: (error: Error) => void; | ||
| }; | ||
|
|
||
| export function useWalletOtpSigner(): OtpSignerFunctions { | ||
| const context = useContext(CrossmintWalletEmailSignerContext); | ||
|
|
||
| if (context == null) { | ||
| throw new Error("useWalletOtpSigner must be used within CrossmintWalletProvider"); | ||
| } | ||
|
|
||
| if (!context.sendOtp || !context.verifyOtp || !context.reject) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit - re these nullable checks? If so, can you pls use |
||
| throw new Error("Otp signer functions are not available. Make sure you're using an otp signer wallet."); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error seems a bit hard to parse, do we call these "otp signer wallet" when you create a wallet? Doesnt a wallet have multple signers? If so does only one of them need to have OTP? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehting like "The wallet in context doesn't have any OTP signer configured. Register an OTP signer first before initializing this hook." |
||
| } | ||
|
|
||
| return { | ||
| needsAuth: context.needsAuth, | ||
| sendOtp: context.sendOtp, | ||
| verifyOtp: context.verifyOtp, | ||
| reject: context.reject, | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,5 +14,6 @@ export { | |
| type Transaction, | ||
| EVMWallet, | ||
| SolanaWallet, | ||
| StellarWallet, | ||
| Wallet, | ||
| } from "@crossmint/wallets-sdk"; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needsAuth -- dont use Auth, name it something like isInitialized (and invert it)