|
1 | 1 | <script setup lang="ts"> |
2 | | -import { createContract, createIndexer } from 'crossbell' |
3 | | -import { onErrorCaptured, ref } from 'vue' |
4 | | -import { useDark, useEventListener, useLocalStorage } from '@vueuse/core' |
5 | | -import { type Address } from 'abitype' |
| 2 | +import { useDark, useEventListener, useLocalStorage } from "@vueuse/core"; |
| 3 | +import type { Address } from "abitype"; |
| 4 | +import { createContract, createIndexer } from "crossbell"; |
| 5 | +import { onErrorCaptured, ref } from "vue"; |
6 | 6 |
|
7 | | -useDark() |
8 | | -useEventListener(window, 'error', (event) => showResult(event)) |
9 | | -useEventListener(window, 'unhandledrejection', (event) => |
10 | | - showResult(event.reason.toString()), |
11 | | -) |
| 7 | +useDark(); |
| 8 | +useEventListener(window, "error", (event) => showResult(event)); |
| 9 | +useEventListener(window, "unhandledrejection", (event) => |
| 10 | + showResult(event.reason.toString()), |
| 11 | +); |
12 | 12 | onErrorCaptured((err) => { |
13 | | - showResult(err) |
14 | | -}) |
| 13 | + showResult(err); |
| 14 | +}); |
15 | 15 |
|
16 | | -const metamask = window.ethereum |
17 | | -const contract = createContract(metamask) |
| 16 | +const metamask = window.ethereum; |
| 17 | +const contract = createContract(metamask); |
18 | 18 |
|
19 | | -const indexer = createIndexer() |
| 19 | +const indexer = createIndexer(); |
20 | 20 |
|
21 | | -const address = useLocalStorage<Address>('address', '0x') |
22 | | -const characterId = useLocalStorage('characterId', '') |
23 | | -const handle = useLocalStorage('handle', '') |
24 | | -const result = ref('') |
25 | | -const loading = ref(false) |
| 21 | +const address = useLocalStorage<Address>("address", "0x"); |
| 22 | +const characterId = useLocalStorage("characterId", ""); |
| 23 | +const handle = useLocalStorage("handle", ""); |
| 24 | +const result = ref(""); |
| 25 | +const loading = ref(false); |
26 | 26 |
|
27 | 27 | async function connect() { |
28 | | - await showResult(contract.walletClient.requestAddresses()) |
| 28 | + await showResult(contract.walletClient.requestAddresses()); |
29 | 29 | } |
30 | 30 |
|
31 | 31 | async function showResult(p: any) { |
32 | | - loading.value = true |
33 | | - try { |
34 | | - result.value = JSON.stringify( |
35 | | - await p, |
36 | | - (key: string, value: any) => |
37 | | - typeof value === 'bigint' ? value.toString() : value, |
38 | | - 2, |
39 | | - ) |
40 | | - } catch (err: any) { |
41 | | - result.value = err |
42 | | - } finally { |
43 | | - loading.value = false |
44 | | - } |
| 32 | + loading.value = true; |
| 33 | + try { |
| 34 | + result.value = JSON.stringify( |
| 35 | + await p, |
| 36 | + (key: string, value: any) => |
| 37 | + typeof value === "bigint" ? value.toString() : value, |
| 38 | + 2, |
| 39 | + ); |
| 40 | + } catch (err: any) { |
| 41 | + result.value = err; |
| 42 | + } finally { |
| 43 | + loading.value = false; |
| 44 | + } |
45 | 45 | } |
46 | 46 |
|
47 | 47 | function balance() { |
48 | | - showResult( |
49 | | - contract.csb.getBalance({ |
50 | | - owner: address.value, |
51 | | - }), |
52 | | - ) |
| 48 | + showResult( |
| 49 | + contract.csb.getBalance({ |
| 50 | + owner: address.value, |
| 51 | + }), |
| 52 | + ); |
53 | 53 | } |
54 | 54 |
|
55 | 55 | function transfer() { |
56 | | - showResult( |
57 | | - contract.csb.transfer({ |
58 | | - toAddress: address.value, |
59 | | - amount: 0, |
60 | | - }), |
61 | | - ) |
| 56 | + showResult( |
| 57 | + contract.csb.transfer({ |
| 58 | + toAddress: address.value, |
| 59 | + amount: 0, |
| 60 | + }), |
| 61 | + ); |
62 | 62 | } |
63 | 63 |
|
64 | 64 | function getPrimaryHandle() { |
65 | | - showResult( |
66 | | - contract.character.getPrimaryId({ |
67 | | - address: address.value, |
68 | | - }), |
69 | | - ) |
| 65 | + showResult( |
| 66 | + contract.character.getPrimaryId({ |
| 67 | + address: address.value, |
| 68 | + }), |
| 69 | + ); |
70 | 70 | } |
71 | 71 |
|
72 | 72 | function getCharacterByHandle() { |
73 | | - showResult( |
74 | | - contract.character.getByHandle({ |
75 | | - handle: handle.value, |
76 | | - }), |
77 | | - ) |
| 73 | + showResult( |
| 74 | + contract.character.getByHandle({ |
| 75 | + handle: handle.value, |
| 76 | + }), |
| 77 | + ); |
78 | 78 | } |
79 | 79 |
|
80 | 80 | function getCharacter() { |
81 | | - showResult( |
82 | | - contract.character.get({ |
83 | | - characterId: characterId.value, |
84 | | - }), |
85 | | - ) |
| 81 | + showResult( |
| 82 | + contract.character.get({ |
| 83 | + characterId: characterId.value, |
| 84 | + }), |
| 85 | + ); |
86 | 86 | } |
87 | 87 |
|
88 | 88 | function setPrimaryCharacterId() { |
89 | | - showResult( |
90 | | - contract.character.setPrimaryId({ |
91 | | - characterId: +characterId.value, |
92 | | - }), |
93 | | - ) |
| 89 | + showResult( |
| 90 | + contract.character.setPrimaryId({ |
| 91 | + characterId: +characterId.value, |
| 92 | + }), |
| 93 | + ); |
94 | 94 | } |
95 | 95 |
|
96 | 96 | function getCharacters() { |
97 | | - showResult(indexer.character.getMany(address.value)) |
| 97 | + showResult(indexer.character.getMany(address.value)); |
98 | 98 | } |
99 | 99 |
|
100 | 100 | function getNotes() { |
101 | | - showResult(indexer.note.getMany({ characterId: characterId.value })) |
| 101 | + showResult(indexer.note.getMany({ characterId: characterId.value })); |
102 | 102 | } |
103 | 103 | function getFeeds() { |
104 | | - showResult(indexer.feed.getManyByCharacter(characterId.value)) |
| 104 | + showResult(indexer.feed.getManyByCharacter(characterId.value)); |
105 | 105 | } |
106 | 106 | </script> |
107 | 107 |
|
|
0 commit comments