https://github.com/leapwallet/leap-near-sdk-react-native-example
https://github.com/leapwallet/leap-near-sdk-react-native-example
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/leapwallet/leap-near-sdk-react-native-example
- Owner: leapwallet
- Created: 2023-01-09T06:03:11.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-03-22T04:11:35.000Z (about 2 years ago)
- Last Synced: 2024-12-27T17:30:20.395Z (5 months ago)
- Language: Java
- Size: 493 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# leap-near-sdk-react-native-example
The above example works for the webapp built using `leap-near-sdk` version 1.1.0 or above
Here, is the sample snippet needs to be used in your webapp to support the mobile.
```ts
const setLeapRedirectURL = () => {
const params = window.location.search.substr(1).split('&');
params.forEach((param) => {
if(param.split("=")[0] === 'leapRedirectURL') {
localStorage.setItem('leapRedirectURL', param.split("=")[1])
}
})
}const autoLogin = async () => {
setLeapRedirectURL();
const sdk = await LeapNearSdk.init({
auth_service: 'web3auth',
authConfig: { appName: 'Leap near board', theme: 'dark', isRedirect: true},
networkId: 'testnet',
})
const token = await sdk.auth?.getUserToken();
if(token) {
await sdk.auth?.connectWithToken(token);
const signedData = await sdk?.auth?.getUser();
console.log(signedData?.address);
const redirectURL = localStorage.getItem('leapRedirectURL') || 'leap-near-react-native://';
(window as Window).location = `${redirectURL}?LeapNearAddress=${signedData?.address}`;
}
else {
await sdk?.auth?.mobileLogin()
}
}autoLogin();
```
https://user-images.githubusercontent.com/110881421/211249655-5379f909-47c9-42dd-9216-359c4abc46ec.mov