some minor ux impros
This commit is contained in:
parent
61ba4d0e4f
commit
c13047e281
@ -1,23 +1,21 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { signMessageWithPKP } from "$lib/services/signMessage";
|
import { signMessageWithPKP } from "$lib/services/signMessage";
|
||||||
import { walletState, messageToSign, messageSignature } from "$lib/stores.js";
|
import { walletState, signRequest } from "$lib/stores.js";
|
||||||
|
|
||||||
let currentPKP;
|
let currentPKP;
|
||||||
let sessionSigs;
|
let sessionSigs;
|
||||||
let message;
|
let message;
|
||||||
let signature;
|
let signature;
|
||||||
|
let status = "WAITING FOR SIGNATURE";
|
||||||
|
|
||||||
walletState.subscribe((value) => {
|
walletState.subscribe((value) => {
|
||||||
currentPKP = value.pkps[0];
|
currentPKP = value.pkps[0];
|
||||||
sessionSigs = value.sessionSigs;
|
sessionSigs = value.sessionSigs;
|
||||||
});
|
});
|
||||||
|
|
||||||
messageToSign.subscribe((value) => {
|
signRequest.subscribe((value) => {
|
||||||
message = value;
|
message = value.messageToSign;
|
||||||
});
|
signature = value.signature;
|
||||||
|
|
||||||
messageSignature.subscribe((value) => {
|
|
||||||
signature = value;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
async function signMessage() {
|
async function signMessage() {
|
||||||
@ -25,17 +23,27 @@
|
|||||||
if (result.error) {
|
if (result.error) {
|
||||||
console.error(result.error);
|
console.error(result.error);
|
||||||
} else {
|
} else {
|
||||||
messageSignature.set(result.messageSignature);
|
(status = "SIGNED"),
|
||||||
|
signRequest.set({
|
||||||
|
messageToSign: message,
|
||||||
|
signature: result.messageSignature,
|
||||||
|
drawer: true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function declineSign() {
|
function declineSign() {
|
||||||
messageSignature.set(null);
|
signRequest.set({
|
||||||
|
messageToSign: {},
|
||||||
|
signature: null,
|
||||||
|
drawer: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="flex flex-col items-center justify-center h-full space-y-4">
|
<div class="flex flex-col items-center justify-center h-full space-y-4">
|
||||||
<p class="text-lg break-words">{JSON.stringify(message)}</p>
|
<p class="text-sm font-bold">{status}</p>
|
||||||
|
<p class="text-lg break-words max-w-2/3">{JSON.stringify(message)}</p>
|
||||||
{#if signature}
|
{#if signature}
|
||||||
<p class="text-sm font-bold break-words">
|
<p class="text-sm font-bold break-words">
|
||||||
Signature: {JSON.stringify(signature)}
|
Signature: {JSON.stringify(signature)}
|
||||||
|
@ -3,14 +3,12 @@
|
|||||||
import walletMachine from "./machines/walletMachine";
|
import walletMachine from "./machines/walletMachine";
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import Icon from "@iconify/svelte";
|
import Icon from "@iconify/svelte";
|
||||||
import { walletState } from "./stores";
|
import { walletState, signRequest } from "./stores";
|
||||||
import { messageToSign } from "./stores";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
signInWithGoogle,
|
signInWithGoogle,
|
||||||
startSignIn as startSignInService,
|
startSignIn as startSignInService,
|
||||||
} from "./services/signInWithGoogle";
|
} from "./services/signInWithGoogle";
|
||||||
import Signer from "./Signer.svelte";
|
|
||||||
import { getDrawerStore } from "@skeletonlabs/skeleton";
|
import { getDrawerStore } from "@skeletonlabs/skeleton";
|
||||||
|
|
||||||
const { state, send } = useMachine(walletMachine);
|
const { state, send } = useMachine(walletMachine);
|
||||||
@ -45,13 +43,24 @@
|
|||||||
send("LOGOUT");
|
send("LOGOUT");
|
||||||
}
|
}
|
||||||
|
|
||||||
function signRequest() {
|
function signRequestTrigger() {
|
||||||
|
signRequest.set({
|
||||||
|
status: "SIGN REQUEST",
|
||||||
|
messageToSign: { hello: "test" },
|
||||||
|
signature: null,
|
||||||
|
drawer: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$: if ($signRequest.drawer) {
|
||||||
const settings = { position: "bottom", id: "signMessage" };
|
const settings = { position: "bottom", id: "signMessage" };
|
||||||
drawerStore.open(settings);
|
drawerStore.open(settings);
|
||||||
messageToSign.set({ hello: "test" });
|
} else {
|
||||||
|
drawerStore.close();
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- ... existing markup ... -->
|
||||||
{#if $state.matches("sessionAvailable") || $state.matches("creatingSession") || $state.matches("signIn")}
|
{#if $state.matches("sessionAvailable") || $state.matches("creatingSession") || $state.matches("signIn")}
|
||||||
{#if $state.matches("signIn")}
|
{#if $state.matches("signIn")}
|
||||||
<div class="w-1/3">
|
<div class="w-1/3">
|
||||||
@ -80,8 +89,10 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button on:click={signRequest} type="button" class="btn variant-filled"
|
<button
|
||||||
>SignRequest</button
|
on:click={signRequestTrigger}
|
||||||
|
type="button"
|
||||||
|
class="btn variant-filled">SignRequest</button
|
||||||
>
|
>
|
||||||
<button type="button" class="btn variant-filled" on:click={clearSession}
|
<button type="button" class="btn variant-filled" on:click={clearSession}
|
||||||
>Logout</button
|
>Logout</button
|
||||||
|
@ -4,10 +4,12 @@ export const redirectStore = writable(false);
|
|||||||
|
|
||||||
export const walletState = writable(null);
|
export const walletState = writable(null);
|
||||||
|
|
||||||
export const messageToSign = writable(null);
|
export const signRequest = writable({
|
||||||
|
messageToSign: {},
|
||||||
export const messageSignature = writable(null);
|
signature: null,
|
||||||
|
drawer: false
|
||||||
|
});
|
||||||
|
|
||||||
export const googleSession = writable({
|
export const googleSession = writable({
|
||||||
activeSession: false
|
activeSession: false
|
||||||
});
|
});
|
Loading…
Reference in New Issue
Block a user