Skip to content

Commit

Permalink
Merge pull request #290 from greymass/manual-create
Browse files Browse the repository at this point in the history
Manual Account Creation
  • Loading branch information
aaroncox authored Dec 6, 2024
2 parents 2c98c29 + 7504e2e commit 99b8651
Show file tree
Hide file tree
Showing 6 changed files with 421 additions and 10 deletions.
78 changes: 78 additions & 0 deletions src/lib/components/input/publickey.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<script lang="ts">
import { PublicKey } from '@wharfkit/antelope';
import type { ComponentProps } from 'svelte';
import TextInput from './text.svelte';
interface PublicKeyInputProps extends ComponentProps<typeof TextInput> {
valid?: boolean;
value: PublicKey | undefined;
debug?: boolean;
}
let {
autofocus = false,
ref = $bindable(),
valid = $bindable(false),
value: _value = $bindable(),
debug = false,
...props
}: PublicKeyInputProps = $props();
/** The string value bound to the form input */
let input: string = $state('');
/** The derived public key from the formatted input */
const pubkey: PublicKey | undefined = $derived.by(() => {
try {
return PublicKey.from(input);
} catch (e) {
console.warn(e);
return;
}
});
/** Validation states */
const satisfiesPublicKeyMatch = $derived(
String(pubkey) === input || String(pubkey?.toLegacyString()) === input
);
/** Whether or not the input value is valid */
const satisfies: boolean = $derived(satisfiesPublicKeyMatch);
/** Set the input value from a parent */
export function set(publickey: string) {
input = publickey;
}
/** Set the bindable values on form input changes */
$effect(() => {
valid = satisfies;
if (satisfies) {
_value = pubkey;
} else {
_value = undefined;
}
});
if (debug) {
$inspect({
input,
satisfies
});
}
</script>

<TextInput bind:ref bind:value={input} {autofocus} {...props} />

{#if debug}
<h3>Component State</h3>
<pre>
input (string): "{input}"
Public Key: {pubkey}

---

Valid Input: {satisfies}
Valid Public Key: {satisfiesPublicKeyMatch}
</pre>
{/if}
Loading

0 comments on commit 99b8651

Please sign in to comment.