Skip to content

Commit 22a6e93

Browse files
authored
Showcase to v2 (#143)
* Showcase to v2 * fixup
1 parent a66c3b5 commit 22a6e93

23 files changed

+136
-66
lines changed

examples/showcase/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"@tanstack/react-query": "^5.51.0",
1717
"@types/react-syntax-highlighter": "^15.5.13",
1818
"@x402x/client": "workspace:*",
19-
"@x402x/core": "workspace:*",
19+
"@x402x/core_v2": "workspace:*",
2020
"class-variance-authority": "^0.7.1",
2121
"clsx": "^2.1.1",
2222
"react": "^18.3.0",

examples/showcase/client/src/components/PaymentDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { PaymentStatus } from "./PaymentStatus";
1111
import { usePayment } from "../hooks/usePayment";
1212
import { useNetworkSwitch } from "../hooks/useNetworkSwitch";
1313
import { useNetworkBalances } from "../hooks/useNetworkBalances";
14-
import { formatDefaultAssetAmount } from "@x402x/core";
14+
import { formatDefaultAssetAmount } from "@x402x/core_v2";
1515
import {
1616
Network,
1717
NETWORKS,

examples/showcase/client/src/components/ServerlessPaymentDialog.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { useState, useEffect, useCallback } from "react";
77
import { useAccount, useWalletClient } from "wagmi";
8-
import { TransferHook, calculateFacilitatorFee, formatDefaultAssetAmount } from "@x402x/core";
8+
import { TransferHook, calculateFacilitatorFee, formatDefaultAssetAmount, toCanonicalNetworkKey } from "@x402x/core_v2";
99
import { useX402Client, X402Client } from "@x402x/client";
1010
import type { FeeCalculationResult } from "@x402x/client";
1111
import { useNetworkSwitch } from "../hooks/useNetworkSwitch";
@@ -310,13 +310,13 @@ export function ServerlessPaymentDialog({
310310

311311
// Format amount for display using dynamic decimals
312312
const amountInUsd = selectedNetwork
313-
? formatDefaultAssetAmount(currentAmount, selectedNetwork)
313+
? formatDefaultAssetAmount(currentAmount, toCanonicalNetworkKey(selectedNetwork))
314314
: (parseFloat(currentAmount) / 1_000_000).toFixed(6); // Fallback for network not selected
315315

316316
const totalAmount = feeInfo && selectedNetwork
317317
? formatDefaultAssetAmount(
318318
(BigInt(currentAmount) + BigInt(feeInfo.facilitatorFee)).toString(),
319-
selectedNetwork
319+
toCanonicalNetworkKey(selectedNetwork)
320320
)
321321
: amountInUsd;
322322

examples/showcase/client/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* - Optional UI customization via NETWORK_UI_OVERRIDES
99
*/
1010

11-
import { getSupportedNetworks, getNetworkConfig as getCoreNetworkConfig } from "@x402x/core";
11+
import { getSupportedNetworks, getNetworkConfig as getCoreNetworkConfig } from "@x402x/core_v2";
1212
import { evm } from "x402/types";
1313
import type { Chain } from "viem";
1414

examples/showcase/client/src/hooks/useNFTData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { useState, useEffect, useCallback } from "react";
99
import { createPublicClient, http, type Address } from "viem";
1010
import { NETWORKS, type Network } from "../config";
11-
import { getNetworkConfig } from "@x402x/core";
11+
import { getNetworkConfig } from "@x402x/core_v2";
1212

1313
const NFT_ABI = [
1414
{

examples/showcase/client/src/hooks/useNetworkBalances.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { useState, useEffect } from "react";
77
import { createPublicClient, http, Address, formatUnits } from "viem";
8-
import { getNetworkConfig } from "@x402x/core";
8+
import { getNetworkConfig } from "@x402x/core_v2";
99
import { NETWORKS, Network } from "../config";
1010

1111
// ERC-20 ABI for balanceOf

examples/showcase/client/src/hooks/useRewardTokenData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { useState, useEffect, useCallback } from "react";
99
import { createPublicClient, http, formatUnits, type Address } from "viem";
1010
import { NETWORKS, type Network } from "../config";
11-
import { getNetworkConfig } from "@x402x/core";
11+
import { getNetworkConfig } from "@x402x/core_v2";
1212

1313
const ERC20_ABI = [
1414
{

examples/showcase/client/src/scenarios/ServerlessPointsReward.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import { TransactionResult } from "../components/TransactionResult";
1616
import { CodeBlock } from "../components/CodeBlock";
1717
import { usePaymentFlow } from "../hooks/usePaymentFlow";
1818
import { useAllNetworksRewardTokenData } from "../hooks/useRewardTokenData";
19-
import { RewardHook, parseDefaultAssetAmount, formatDefaultAssetAmount } from "@x402x/core";
19+
import { RewardHook, parseDefaultAssetAmount, formatDefaultAssetAmount, toCanonicalNetworkKey } from "@x402x/core_v2";
2020
import { NETWORKS } from "../config";
2121
import pointsRewardCode from "../code-examples/points-reward.ts?raw";
2222

2323
// Helper function to get amount for a specific network
2424
const getAmountForNetwork = (network: string): string => {
25-
return parseDefaultAssetAmount("0.1", network); // 0.1 token in network-specific atomic units
25+
return parseDefaultAssetAmount("0.1", toCanonicalNetworkKey(network)); // 0.1 token in network-specific atomic units
2626
};
2727

2828
export function ServerlessPointsReward() {
@@ -366,7 +366,7 @@ export function ServerlessPointsReward() {
366366
label: "Cost",
367367
value: paymentResult.facilitatorFee ? (
368368
<strong>
369-
${formatDefaultAssetAmount(paymentResult.facilitatorFee, paymentResult.network)} facilitator fee
369+
${formatDefaultAssetAmount(paymentResult.facilitatorFee, toCanonicalNetworkKey(paymentResult.network))} facilitator fee
370370
</strong>
371371
) : (
372372
<strong>$0.01 facilitator fee</strong>

examples/showcase/client/src/scenarios/ServerlessRandomNFT.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ import { TransactionResult } from "../components/TransactionResult";
1616
import { CodeBlock } from "../components/CodeBlock";
1717
import { usePaymentFlow } from "../hooks/usePaymentFlow";
1818
import { useAllNetworksNFTData } from "../hooks/useNFTData";
19-
import { NFTMintHook, parseDefaultAssetAmount, formatDefaultAssetAmount } from "@x402x/core";
19+
import { NFTMintHook, parseDefaultAssetAmount, formatDefaultAssetAmount, toCanonicalNetworkKey } from "@x402x/core_v2";
2020
import { NETWORKS } from "../config";
2121
import nftMintCode from "../code-examples/nft-mint.ts?raw";
2222

2323
// Helper function to get amount for a specific network
2424
const getAmountForNetwork = (network: string): string => {
25-
return parseDefaultAssetAmount("0.1", network); // 0.1 token in network-specific atomic units
25+
return parseDefaultAssetAmount("0.1", toCanonicalNetworkKey(network)); // 0.1 token in network-specific atomic units
2626
};
2727

2828
export function ServerlessRandomNFT() {
@@ -354,7 +354,7 @@ export function ServerlessRandomNFT() {
354354
label: "Cost",
355355
value: paymentResult.facilitatorFee ? (
356356
<strong>
357-
${formatDefaultAssetAmount(paymentResult.facilitatorFee, paymentResult.network)} facilitator fee
357+
${formatDefaultAssetAmount(paymentResult.facilitatorFee, toCanonicalNetworkKey(paymentResult.network))} facilitator fee
358358
</strong>
359359
) : (
360360
<strong>$0.01 facilitator fee</strong>

examples/showcase/client/src/scenarios/ServerlessSplitPayment.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111
import { useState } from "react";
1212
import { useAccount } from "wagmi";
13-
import { TransferHook } from "@x402x/core";
13+
import { TransferHook } from "@x402x/core_v2";
1414
import { ServerlessPaymentDialog } from "../components/ServerlessPaymentDialog";
1515
import { ScenarioCard } from "../components/ScenarioCard";
1616
import { PaymentButton } from "../components/PaymentButton";
1717
import { StatusMessage } from "../components/StatusMessage";
1818
import { TransactionResult } from "../components/TransactionResult";
1919
import { CodeBlock } from "../components/CodeBlock";
2020
import { usePaymentFlow } from "../hooks/usePaymentFlow";
21-
import { parseDefaultAssetAmount, formatDefaultAssetAmount } from "@x402x/core";
21+
import { parseDefaultAssetAmount, formatDefaultAssetAmount, toCanonicalNetworkKey } from "@x402x/core_v2";
2222
import { NETWORKS } from "../config";
2323
import splitPaymentCode from "../code-examples/split-payment.ts?raw";
2424

@@ -28,7 +28,7 @@ const DEFAULT_RECIPIENT =
2828

2929
// Helper function to get amount for a specific network
3030
const getAmountForNetwork = (network: string): string => {
31-
return parseDefaultAssetAmount("0.1", network); // 0.1 token in network-specific atomic units
31+
return parseDefaultAssetAmount("0.1", toCanonicalNetworkKey(network)); // 0.1 token in network-specific atomic units
3232
};
3333

3434
interface Split {
@@ -519,7 +519,7 @@ export function ServerlessSplitPayment() {
519519
label: "Cost",
520520
value: paymentResult.facilitatorFee ? (
521521
<strong>
522-
${formatDefaultAssetAmount(paymentResult.facilitatorFee, paymentResult.network)} facilitator fee
522+
${formatDefaultAssetAmount(paymentResult.facilitatorFee, toCanonicalNetworkKey(paymentResult.network))} facilitator fee
523523
</strong>
524524
) : (
525525
<strong>$0.01 facilitator fee</strong>

0 commit comments

Comments
 (0)