Skip to content

Commit 7692574

Browse files
committed
feat: update demo
1 parent acbb7c6 commit 7692574

File tree

3 files changed

+16142
-16079
lines changed

3 files changed

+16142
-16079
lines changed

demo/vue-app-new/src/components/AppDashboard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ const onSwitchChain = async () => {
512512
</Card>
513513

514514
<!-- x402 -->
515-
<X402Tester v-if="isDisplay('ethServices')" class="mb-2" />
515+
<X402Tester v-if="isDisplay('ethServices')" class="mb-2" @print-to-console="printToConsole" />
516516

517517
<!-- SOLANA -->
518518
<Card v-if="isDisplay('solServices')" class="h-auto gap-4 px-4 py-4 mb-2" :shadow="false">

demo/vue-app-new/src/components/X402Tester.vue

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,54 @@ const { isConnected } = useWeb3Auth();
1212
const { chainId, chainNamespace } = useChain();
1313
const { mutateAsync: switchChainAsync } = useSwitchChain();
1414
const { fetchWithPayment } = useX402Fetch();
15+
const emit = defineEmits<{
16+
(e: "print-to-console", title: string, payload?: unknown): void;
17+
}>();
1518
1619
const url = ref(DEFAULT_X402_URL);
1720
const fetchLoading = ref(false);
18-
const result = ref<string | null>(null);
19-
const fetchError = ref<string | null>(null);
2021
2122
const isOnBaseSepolia = ref(false);
2223
24+
const parseConsoleBody = (text: string) => {
25+
try {
26+
return JSON.parse(text);
27+
} catch {
28+
return text;
29+
}
30+
};
31+
2332
watch(chainId, (id) => {
2433
isOnBaseSepolia.value = id?.toLowerCase() === BASE_SEPOLIA_CHAIN_ID.toLowerCase();
2534
}, { immediate: true });
2635
2736
const onSwitchToBaseSepolia = async () => {
2837
fetchLoading.value = true;
2938
try {
30-
result.value = null;
31-
fetchError.value = null;
3239
await switchChainAsync({ chainId: parseInt(BASE_SEPOLIA_CHAIN_ID, 16) });
3340
} catch (err) {
34-
fetchError.value = err instanceof Error ? err.message : String(err);
41+
emit("print-to-console", "x402 network error", err instanceof Error ? err.message : String(err));
3542
} finally {
3643
fetchLoading.value = false;
3744
}
3845
};
3946
4047
const onFetchWithPayment = async () => {
41-
result.value = null;
42-
fetchError.value = null;
4348
fetchLoading.value = true;
4449
try {
4550
const response = await fetchWithPayment({ url: url.value });
4651
const text = await response.text();
47-
result.value = text;
52+
emit("print-to-console", "x402 response", {
53+
url: url.value,
54+
status: response.status,
55+
ok: response.ok,
56+
body: parseConsoleBody(text),
57+
});
4858
} catch (err) {
49-
fetchError.value = err instanceof Error ? err.message : String(err);
59+
emit("print-to-console", "x402 error", {
60+
url: url.value,
61+
message: err instanceof Error ? err.message : String(err),
62+
});
5063
} finally {
5164
fetchLoading.value = false;
5265
}
@@ -117,16 +130,5 @@ const onFetchWithPayment = async () => {
117130
>
118131
Fetch with Payment
119132
</Button>
120-
121-
<!-- Result -->
122-
<div v-if="result !== null || fetchError" class="rounded-lg overflow-hidden text-xs">
123-
<div v-if="fetchError" class="bg-red-50 border border-red-200 px-3 py-2 text-red-600 break-words">
124-
<span class="font-semibold">Error: </span>{{ fetchError }}
125-
</div>
126-
<div v-else class="bg-green-50 border border-green-200 px-3 py-2">
127-
<div class="font-semibold text-green-700 mb-1">Response</div>
128-
<pre class="text-gray-800 whitespace-pre-wrap break-words max-h-48 overflow-y-auto">{{ result }}</pre>
129-
</div>
130-
</div>
131133
</Card>
132134
</template>

0 commit comments

Comments
 (0)