Skip to content

Commit

Permalink
bare app: Add request method function
Browse files Browse the repository at this point in the history
  • Loading branch information
yashovardhan committed Sep 25, 2024
1 parent 841c940 commit 4ef529e
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions demo/rn-bare-example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ export default function App() {
};

// IMP START - Blockchain Calls
const getAccounts = async () => {
const getAccounts = async (): Promise<string> => {
if (!provider) {
uiConsole("provider not set");
return;
return "";
}
setConsole("Getting account");
// For ethers v5
Expand All @@ -139,6 +139,7 @@ export default function App() {
// Get user's Ethereum public address
const address = signer.getAddress();
uiConsole(address);
return address;
};

const getBalance = async () => {
Expand Down Expand Up @@ -204,13 +205,30 @@ export default function App() {
setConsole(JSON.stringify(args || {}, null, 2) + "\n\n\n\n" + console);
};

const requestSignature = async () => {
if (!web3auth) {
setConsole("Web3auth not initialized");
return;
}
try {
const address: string = await getAccounts();

const params = ["Hello World", address];
const res = await web3auth.request(chainConfig, "personal_sign", params);
uiConsole(res);
} catch (error) {
uiConsole("Error in requestSignature:", error);
}
};

const loggedInView = (
<View style={styles.buttonArea}>
<Button title="Get User Info" onPress={() => uiConsole(web3auth.userInfo())} />
<Button title="Get Accounts" onPress={() => getAccounts()} />
<Button title="Get Balance" onPress={() => getBalance()} />
<Button title="Sign Message" onPress={() => signMessage()} />
<Button title="Show Wallet UI" onPress={() => launchWalletServices()} />
<Button title="Request Signature UI" onPress={() => requestSignature()} />
<Button title="Log Out" onPress={logout} />
</View>
);
Expand Down

0 comments on commit 4ef529e

Please sign in to comment.