forked from cerc-io/laconic-wallet
* Connect with dapp using WalletConnect * Pair dapp with wallet * Sign message taken from dapp and return the signature * Add todos * Move wallet connect functions to seperate screen * Change ui * Change ui for wc modals * Add styles * Remove border radius at the bottom * Make review changes * Add dependancy to useEffect * Move pairing modal methods --------- Co-authored-by: Adw8 <adwait@deepstacksoft.com>
65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
// https://medium.com/walletconnect/how-to-build-a-wallet-in-react-native-with-the-web3wallet-sdk-b6f57bf02f9a
|
|
// TODO: check and remove if not used
|
|
|
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
import EIP155Lib from './EIP155Lib';
|
|
|
|
export let wallet1: EIP155Lib;
|
|
export let wallet2: EIP155Lib;
|
|
export let eip155Wallets: Record<string, EIP155Lib>;
|
|
export let eip155Addresses: string[];
|
|
|
|
export let address1: string;
|
|
let address2: string;
|
|
|
|
/**
|
|
* Utilities
|
|
*/
|
|
export const setLocalStorage = async (mnemonic: any) => {
|
|
try {
|
|
const value = await AsyncStorage.setItem('EIP155_MNEMONIC_1', mnemonic);
|
|
if (value !== null) {
|
|
return value;
|
|
}
|
|
} catch (e) {
|
|
console.log('setLocalStorage Error:', e);
|
|
}
|
|
};
|
|
|
|
export const getLocalStorage = async () => {
|
|
try {
|
|
const value = await AsyncStorage.getItem('EIP155_MNEMONIC_1');
|
|
if (value !== null) {
|
|
return value;
|
|
}
|
|
} catch (e) {
|
|
console.log('getLocalStorage Error:', e);
|
|
}
|
|
};
|
|
|
|
// Function to create or restore a wallet
|
|
export async function createOrRestoreEIP155Wallet() {
|
|
let mnemonic1 = await getLocalStorage();
|
|
|
|
if (mnemonic1) {
|
|
wallet1 = EIP155Lib.init({ mnemonic: mnemonic1 });
|
|
} else {
|
|
wallet1 = EIP155Lib.init({});
|
|
}
|
|
|
|
// @notice / Warning!!! : This is a test wallet, do not use it for real transactions
|
|
setLocalStorage(wallet1?.getMnemonic());
|
|
address1 = wallet1.getAddress();
|
|
|
|
eip155Wallets = {
|
|
[address1]: wallet1,
|
|
[address2]: wallet2,
|
|
};
|
|
eip155Addresses = Object.keys(eip155Wallets);
|
|
|
|
return {
|
|
eip155Wallets,
|
|
eip155Addresses,
|
|
};
|
|
}
|