-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5cddd08
commit fd502fc
Showing
15 changed files
with
332 additions
and
181 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<script lang="ts"> | ||
import { connectAccount } from '$lib/rpc-methods'; | ||
let account = { name: '', publicKey: '' }; | ||
type AccountData = { | ||
accountName: string; | ||
activeKey: string; | ||
ownerKey: string; | ||
chainId: string; | ||
}; | ||
async function handleFormSubmit(event: Event) { | ||
const formData = new FormData(event.target as HTMLFormElement); | ||
const accountData: AccountData = { | ||
accountName: formData.get('account') as string, | ||
activeKey: formData.get('publicKey') as string, | ||
ownerKey: formData.get('publicKey') as string, | ||
chainId: '73e4385a2708e6d7048834fbc1079f2fabb17b3c125b146af438971e90716c4d' | ||
}; | ||
const name = await createAccount(accountData, 'https://jungle4.greymass.com'); | ||
if (typeof name !== 'undefined') { | ||
console.log(`Account ${name} created`); | ||
connectAccount(); | ||
} | ||
} | ||
async function createAccount(accountData: AccountData, chainUrl: string) { | ||
const data = { | ||
accountName: accountData.accountName, | ||
activeKey: accountData.activeKey, | ||
ownerKey: accountData.ownerKey, | ||
network: accountData.chainId | ||
}; | ||
try { | ||
const response = await fetch(`${chainUrl}/account/create`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: JSON.stringify(data) | ||
}); | ||
console.log(response); | ||
if (response.status === 201) { | ||
console.log('success:', JSON.stringify(await response.text(), null, 2)); | ||
return accountData.accountName; | ||
} | ||
console.log('failure:', JSON.stringify(await response.text(), null, 2)); | ||
} catch (error) { | ||
console.error('error getting response', error); | ||
} | ||
} | ||
</script> | ||
|
||
<h2>Create Jungle4 Account</h2> | ||
<form on:submit|preventDefault={handleFormSubmit}> | ||
<div> | ||
<label for="account">Name:</label> | ||
<input type="text" id="account" name="account" bind:value={account.name} /> | ||
</div> | ||
<div> | ||
<label for="account">PublicKey:</label> | ||
<input type="text" id="account" name="publicKey" bind:value={account.publicKey} /> | ||
</div> | ||
<button type="submit">Submit</button> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
import { writable } from 'svelte/store'; | ||
|
||
export const accountName = writable<string | null>(null); | ||
|
||
export const accountPermission = writable<string | null>(null); | ||
|
||
export const accountPublicKey = writable<string | null>(null); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { accountName } from './account'; | ||
import { invokeSnap } from './snap'; | ||
|
||
export async function connectAccount() { | ||
const result = await invokeSnap({ method: 'eos_connectAccount' }); | ||
console.log('accountName', result); | ||
accountName.set(result); | ||
} | ||
|
||
export async function getConnectedAccount() { | ||
const account = await invokeSnap({ method: 'eos_getConnectedAccount' }); | ||
console.log('account', account); | ||
accountName.set(account); | ||
// accountPublicKey.set(account.publicKey); | ||
// accountPermission.set(account.permission); | ||
} | ||
|
||
export async function testTransaction() { | ||
const result = await invokeSnap({ method: 'eos_signTransaction' }); | ||
console.log('result', result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.