<script>
	import { onMount } from 'svelte';
	import { PKPEthersWallet } from '@lit-protocol/pkp-ethers';
	import { LOCAL_STORAGE_KEYS } from '@lit-protocol/constants';

	export let pkpWallet;
	export let authSig = null;
	const pkpPubKey =
		'046da3ba67065fd1e2726242ca01cd4601524893f4aa4b0042578fa6cbec28fa8c9a28eb9f7893932fc09717edc9e1db57e157a21eed346247c1db5a722a01f571';

	onMount(async () => {
		const storedAuthSig = await localStorage.getItem(LOCAL_STORAGE_KEYS.AUTH_SIGNATURE);

		if (storedAuthSig) {
			authSig = JSON.parse(storedAuthSig);
			pkpWallet = new PKPEthersWallet({
				controllerAuthSig: authSig,
				pkpPubKey,
				rpc: 'https://rpc.gnosischain.com/'
			});
			await pkpWallet.init();
		} else {
			alert('no authsig parsed from local storage');
		}
	});
</script>

{#if pkpWallet}
	<div class="mb-4 text-lg font-medium">
		PKP Wallet: <span class="text-blue-600">{pkpWallet.address}</span>
	</div>
{/if}
