Skip to content

Commit 4ef529e

Browse files
committed
bare app: Add request method function
1 parent 841c940 commit 4ef529e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

demo/rn-bare-example/App.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ export default function App() {
122122
};
123123

124124
// IMP START - Blockchain Calls
125-
const getAccounts = async () => {
125+
const getAccounts = async (): Promise<string> => {
126126
if (!provider) {
127127
uiConsole("provider not set");
128-
return;
128+
return "";
129129
}
130130
setConsole("Getting account");
131131
// For ethers v5
@@ -139,6 +139,7 @@ export default function App() {
139139
// Get user's Ethereum public address
140140
const address = signer.getAddress();
141141
uiConsole(address);
142+
return address;
142143
};
143144

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

208+
const requestSignature = async () => {
209+
if (!web3auth) {
210+
setConsole("Web3auth not initialized");
211+
return;
212+
}
213+
try {
214+
const address: string = await getAccounts();
215+
216+
const params = ["Hello World", address];
217+
const res = await web3auth.request(chainConfig, "personal_sign", params);
218+
uiConsole(res);
219+
} catch (error) {
220+
uiConsole("Error in requestSignature:", error);
221+
}
222+
};
223+
207224
const loggedInView = (
208225
<View style={styles.buttonArea}>
209226
<Button title="Get User Info" onPress={() => uiConsole(web3auth.userInfo())} />
210227
<Button title="Get Accounts" onPress={() => getAccounts()} />
211228
<Button title="Get Balance" onPress={() => getBalance()} />
212229
<Button title="Sign Message" onPress={() => signMessage()} />
213230
<Button title="Show Wallet UI" onPress={() => launchWalletServices()} />
231+
<Button title="Request Signature UI" onPress={() => requestSignature()} />
214232
<Button title="Log Out" onPress={logout} />
215233
</View>
216234
);

0 commit comments

Comments
 (0)