Skip to content

Commit

Permalink
refactor: move playground types to separate file (#1625)
Browse files Browse the repository at this point in the history
Co-authored-by: dschlabach <daniel.schlabach@coinbase.com>
  • Loading branch information
dschlabach and dschlabach authored Nov 20, 2024
1 parent 69a759f commit 56ca67d
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 61 deletions.
59 changes: 9 additions & 50 deletions playground/nextjs-app-router/components/AppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,21 @@
// AppContext.js
import { ENVIRONMENT, ENVIRONMENT_VARIABLES } from '@/lib/constants';
import {
type CheckoutOptions,
CheckoutTypes,
type ComponentMode,
type ComponentTheme,
OnchainKitComponent,
type Paymaster,
TransactionTypes,
} from '@/types/onchainkit';
import { OnchainKitProvider } from '@coinbase/onchainkit';
import type React from 'react';
import { createContext, useEffect, useState } from 'react';
import { useConnect, useConnectors } from 'wagmi';
import { base } from 'wagmi/chains';
import { WalletPreference } from './form/wallet-type';

export enum OnchainKitComponent {
Fund = 'fund',
Identity = 'identity',
IdentityCard = 'identity-card',
Checkout = 'checkout',
Swap = 'swap',
SwapDefault = 'swap-default',
Transaction = 'transaction',
TransactionDefault = 'transaction-default',
Wallet = 'wallet',
WalletDefault = 'wallet-default',
NFTCard = 'nft-card',
NFTCardDefault = 'nft-card-default',
NFTMintCard = 'nft-mint-card',
NFTMintCardDefault = 'nft-mint-card-default',
}

export enum TransactionTypes {
Calls = 'calls',
Contracts = 'contracts',
CallsPromise = 'callsPromise',
ContractsPromise = 'contractsPromise',
CallsCallback = 'callsCallback',
ContractsCallback = 'contractsCallback',
}

export type Paymaster = {
url: string;
enabled: boolean;
};

export type CheckoutOptions = {
chargeId?: string;
productId?: string;
};

export enum CheckoutTypes {
ChargeID = 'chargeId',
ProductID = 'productId',
}

export type ComponentTheme =
| 'base'
| 'cyberpunk'
| 'default'
| 'hacker'
| 'none'; // Simulates an undefined theme field

export type ComponentMode = 'auto' | 'light' | 'dark';

type State = {
activeComponent?: OnchainKitComponent;
setActiveComponent?: (component: OnchainKitComponent) => void;
Expand Down
3 changes: 2 additions & 1 deletion playground/nextjs-app-router/components/Demo.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import { AppContext, OnchainKitComponent } from '@/components/AppProvider';
import { AppContext } from '@/components/AppProvider';
import { cn } from '@/lib/utils';
import { OnchainKitComponent } from '@/types/onchainkit';
import { useContext, useEffect, useState } from 'react';
import DemoOptions from './DemoOptions';
import CheckoutDemo from './demo/Checkout';
Expand Down
2 changes: 1 addition & 1 deletion playground/nextjs-app-router/components/DemoOptions.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentMode } from '@/components/form/component-mode';
import { ComponentTheme } from '@/components/form/component-theme';
import { PaymasterUrl } from '@/components/form/paymaster';
import { OnchainKitComponent } from './AppProvider';
import { OnchainKitComponent } from '@/types/onchainkit';
import { ActiveComponent } from './form/active-component';
import { Chain } from './form/chain';
import { CheckoutOptions } from './form/checkout-options';
Expand Down
4 changes: 2 additions & 2 deletions playground/nextjs-app-router/components/demo/Checkout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { CheckoutTypes } from '@/types/onchainkit';
import {
Checkout,
CheckoutButton,
Expand All @@ -6,8 +7,7 @@ import {
import type { LifecycleStatus } from '@coinbase/onchainkit/checkout';
import { useCallback, useMemo } from 'react';
import { useContext } from 'react';
import { AppContext, CheckoutTypes } from '../AppProvider';

import { AppContext } from '../AppProvider';
export default function CheckoutDemo() {
const { checkoutTypes, checkoutOptions, isSponsored } =
useContext(AppContext);
Expand Down
3 changes: 2 additions & 1 deletion playground/nextjs-app-router/components/demo/Transaction.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { clickCalls, clickContracts } from '@/lib/transactions';
import type { Call } from '@/onchainkit/esm/transaction/types';
import type { LifecycleStatus } from '@/onchainkit/src/transaction';
import { TransactionTypes } from '@/types/onchainkit';
import {
Transaction,
TransactionButton,
Expand All @@ -15,7 +16,7 @@ import {
} from '@coinbase/onchainkit/transaction';
import { useCallback, useContext, useEffect, useMemo } from 'react';
import type { ContractFunctionParameters } from 'viem';
import { AppContext, TransactionTypes } from '../AppProvider';
import { AppContext } from '../AppProvider';

function TransactionDemo() {
const { chainId, transactionType, isSponsored } = useContext(AppContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useCapabilities } from '@/lib/hooks';
import { clickCalls, clickContracts } from '@/lib/transactions';
import { TransactionTypes } from '@/types/onchainkit';
import { TransactionDefault } from '@coinbase/onchainkit/transaction';
import { useCallback, useContext, useEffect } from 'react';
import { AppContext, TransactionTypes } from '../AppProvider';
import { AppContext } from '../AppProvider';

export default function TransactionDefaultDemo() {
const { chainId, transactionType } = useContext(AppContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { OnchainKitComponent } from '@/types/onchainkit';
import { useContext } from 'react';
import { AppContext, OnchainKitComponent } from '../AppProvider';
import { AppContext } from '../AppProvider';

export function ActiveComponent() {
const { activeComponent, setActiveComponent } = useContext(AppContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
import { CheckoutTypes } from '@/types/onchainkit';
import { useContext } from 'react';
import { useState } from 'react';
import { AppContext, CheckoutTypes } from '../AppProvider';
import { AppContext } from '../AppProvider';

export function CheckoutOptions() {
const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import type { ComponentMode as ComponentModeReact } from '@/types/onchainkit';
import { useContext } from 'react';
import { AppContext } from '../AppProvider';
import type { ComponentMode as ComponentModeReact } from '../AppProvider';

export function ComponentMode() {
const { componentMode, setComponentMode } = useContext(AppContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import type { ComponentTheme as ComponentThemeType } from '@/types/onchainkit';
import { useContext } from 'react';
import { AppContext } from '../AppProvider';
import type { ComponentTheme as ComponentThemeType } from '../AppProvider';

export function ComponentTheme() {
const { componentTheme, setComponentTheme } = useContext(AppContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import {
SelectTrigger,
SelectValue,
} from '@/components/ui/select';
import { TransactionTypes } from '@/types/onchainkit';
import { useContext } from 'react';
import { AppContext, TransactionTypes } from '../AppProvider';
import { AppContext } from '../AppProvider';

export function TransactionOptions() {
const { transactionType, setTransactionType } = useContext(AppContext);
Expand Down
49 changes: 49 additions & 0 deletions playground/nextjs-app-router/types/onchainkit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export enum OnchainKitComponent {
Fund = 'fund',
Identity = 'identity',
IdentityCard = 'identity-card',
Checkout = 'checkout',
Swap = 'swap',
SwapDefault = 'swap-default',
Transaction = 'transaction',
TransactionDefault = 'transaction-default',
Wallet = 'wallet',
WalletDefault = 'wallet-default',
NFTCard = 'nft-card',
NFTCardDefault = 'nft-card-default',
NFTMintCard = 'nft-mint-card',
NFTMintCardDefault = 'nft-mint-card-default',
}

export enum TransactionTypes {
Calls = 'calls',
Contracts = 'contracts',
CallsPromise = 'callsPromise',
ContractsPromise = 'contractsPromise',
CallsCallback = 'callsCallback',
ContractsCallback = 'contractsCallback',
}

export type Paymaster = {
url: string;
enabled: boolean;
};

export type CheckoutOptions = {
chargeId?: string;
productId?: string;
};

export enum CheckoutTypes {
ChargeID = 'chargeId',
ProductID = 'productId',
}

export type ComponentTheme =
| 'base'
| 'cyberpunk'
| 'default'
| 'hacker'
| 'none'; // Simulates an undefined theme field

export type ComponentMode = 'auto' | 'light' | 'dark';

0 comments on commit 56ca67d

Please sign in to comment.