refactoed mint and create session
This commit is contained in:
@ -1,11 +1,10 @@
|
||||
<script lang="ts">
|
||||
import { onMount, tick } from 'svelte';
|
||||
import { isSignInRedirect, getProviderFromUrl } from '@lit-protocol/lit-auth-client';
|
||||
import { IRelayPKP } from '@lit-protocol/types';
|
||||
import type { IRelayPKP } from '@lit-protocol/types';
|
||||
import { ProviderType } from '@lit-protocol/constants';
|
||||
import { LitAccessControlConditionResource, LitAbility } from '@lit-protocol/auth-helpers';
|
||||
import { createMessage } from '$lib/services/messages';
|
||||
// import { setupLitProvider } from '$lib/services/provider/setupLitProvider.ts';
|
||||
import { createLitSession } from '$lib/services/createLitSession/createLitSession';
|
||||
|
||||
const redirectUri = 'http://localhost:5173/';
|
||||
let view = 'sign_in';
|
||||
@ -131,30 +130,11 @@
|
||||
isLoading = true;
|
||||
error = null;
|
||||
try {
|
||||
console.log('Minting started...');
|
||||
createMessage({
|
||||
text: 'Minting started...',
|
||||
sender: '$lib/components/GoogleAuth.svelte',
|
||||
type: 'SYSTEM'
|
||||
});
|
||||
view = 'MINTING';
|
||||
|
||||
// Using the global provider variable, so no need to call getProvider again
|
||||
const txHash: string = await provider.mintPKPThroughRelayer(authMethod);
|
||||
const response = await provider.relay.pollRequestUntilTerminalState(txHash);
|
||||
if (response.status !== 'Succeeded') {
|
||||
throw new Error('Minting failed');
|
||||
}
|
||||
const newPKP: IRelayPKP = {
|
||||
tokenId: response.pkpTokenId,
|
||||
publicKey: response.pkpPublicKey,
|
||||
ethAddress: response.pkpEthAddress
|
||||
};
|
||||
|
||||
const newPKP: IRelayPKP = await mintPkp(provider, authMethod); // Ensure provider implements IProvider
|
||||
pkps = [...pkps, newPKP];
|
||||
|
||||
await createSession(newPKP); // Moved the call to createSession() here
|
||||
view = 'MINTED'; // Update the view after the session is created
|
||||
await createSession(newPKP);
|
||||
view = 'MINTED';
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
error = err;
|
||||
@ -162,12 +142,6 @@
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
console.log('Minted a new PKP.');
|
||||
createMessage({
|
||||
text: 'Minted a new PKP.',
|
||||
sender: '$lib/components/GoogleAuth.svelte',
|
||||
type: 'SYSTEM'
|
||||
});
|
||||
}
|
||||
|
||||
async function createSession(pkp: IRelayPKP) {
|
||||
@ -182,21 +156,9 @@
|
||||
});
|
||||
view = 'CREATING_SESSION';
|
||||
|
||||
const litResource = new LitAccessControlConditionResource('*');
|
||||
sessionSigs = await provider.getSessionSigs({
|
||||
pkpPublicKey: pkp.publicKey,
|
||||
authMethod,
|
||||
sessionSigsParams: {
|
||||
chain: 'ethereum',
|
||||
resourceAbilityRequests: [
|
||||
{
|
||||
resource: litResource,
|
||||
ability: LitAbility.PKPSigning
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
sessionSigs = await createLitSession(provider, pkp.publicKey, authMethod);
|
||||
currentPKP = pkp;
|
||||
|
||||
createMessage({
|
||||
text: 'Session created.',
|
||||
sender: '$lib/components/GoogleAuth.svelte',
|
||||
@ -210,9 +172,6 @@
|
||||
} finally {
|
||||
isLoading = false;
|
||||
}
|
||||
|
||||
console.log('Session created.');
|
||||
view = 'SESSION_CREATED';
|
||||
}
|
||||
|
||||
function resetView() {
|
||||
|
Reference in New Issue
Block a user