@hanzo/commerce 1.1.11 → 1.1.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,12 +30,6 @@ const ContactInfo: React.FC<{
30
30
  <Form {...form}>
31
31
  <form className='text-left'>
32
32
  <div className='flex flex-col gap-4'>
33
- <div className='flex gap-4 items-center'>
34
- <User />
35
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
36
- heading: { text: `Contact Info`, level: 4 },
37
- } as EnhHeadingBlock}/>
38
- </div>
39
33
  <div className='flex flex-col sm:flex-row gap-4'>
40
34
  <FormField
41
35
  control={form.control}
@@ -8,10 +8,10 @@ import { zodResolver } from '@hookform/resolvers/zod'
8
8
  import * as z from 'zod'
9
9
  import { useForm } from 'react-hook-form'
10
10
 
11
- import { ApplyTypography, Button, Main, Separator } from '@hanzo/ui/primitives'
11
+ import { Button, Main, Separator, Toaster } from '@hanzo/ui/primitives'
12
12
  import { cn } from '@hanzo/ui/util'
13
13
  import { useAuth } from '@hanzo/auth/service'
14
- import { LoginComponent } from '@hanzo/auth/components'
14
+ import { LoginComponent, AuthWidget } from '@hanzo/auth/components'
15
15
 
16
16
  import ShippingInfo from './shipping-info'
17
17
  import ThankYou from './thank-you'
@@ -86,45 +86,45 @@ const Checkout: React.FC<{toggleCheckout: () => void}> = observer(({toggleChecko
86
86
  const steps = [step1, step2, step3, step4]
87
87
 
88
88
  return (
89
- <div className="fixed top-0 left-0 !max-w-none w-full h-full min-h-screen bg-background z-[51]">
90
- <Main className='grid grid-cols-5 justify-center gap-8 overflow-y-auto h-full'>
91
- <Button
92
- variant='ghost'
93
- size='icon'
94
- className='absolute sm:ml-2 sm:mt-2'
95
- onClick={() => {
96
- setCurrentStep(0)
97
- toggleCheckout()
98
- }}
99
- >
100
- <ChevronLeft/>
101
- </Button>
102
-
103
- <div className='col-span-2 hidden md:flex'>
104
- <Cart hideCheckout className='fixed justify-center border-none mt-10 w-1/3 max-w-[40rem]'/>
105
- </div>
89
+ <div className="fixed top-0 left-0 !max-w-none w-full h-full min-h-screen bg-background z-[51]">
90
+ <Toaster/>
91
+ <Main className='flex flex-col gap-1 h-full'>
92
+ <div className='flex justify-between'>
93
+ <Button
94
+ variant='ghost'
95
+ size='icon'
96
+ className='sm:ml-2 sm:mt-2'
97
+ onClick={() => {
98
+ setCurrentStep(0)
99
+ toggleCheckout()
100
+ }}
101
+ >
102
+ <ChevronLeft/>
103
+ </Button>
104
+ <AuthWidget/>
105
+ </div>
106
+
107
+ <div className='grid grid-cols-5 justify-center gap-8 h-full'>
108
+ <div className='col-span-2 hidden md:flex'>
109
+ <Cart hideCheckout className='fixed justify-center border-none mt-10 w-1/3 max-w-[40rem]'/>
110
+ </div>
106
111
 
107
- <div className='flex flex-col gap-8 sm:gap-14 col-span-5 md:col-span-3 max-w-[40rem] mx-auto'>
108
- <ApplyTypography className='w-full'>
109
- <h3 className='!text-center w-1/2 mx-auto sm:w-full sm:mt-5'>FINALIZE PAYMENT</h3>
110
- </ApplyTypography>
111
- <div className='flex gap-2 mx-auto items-center text-xxs sm:text-base'>
112
- <div className={cn('w-6 h-6 rounded-full border border-foreground flex flex-col justify-center items-center', currentStep === 1 ? 'bg-foreground text-muted-4' : '')}>
113
- 1
114
- <div className='relative text-foreground top-2 h-0 whitespace-nowrap'>Contact info</div>
115
- </div>
116
- <Separator className='w-[4rem] sm:w-[6rem]'/>
117
- <div className={cn('w-6 h-6 rounded-full border border-foreground flex flex-col justify-center items-center', currentStep === 2 ? 'bg-foreground text-muted-4' : '')}>
118
- 2
119
- <div className='relative text-foreground top-2 h-0 whitespace-nowrap'>Payment</div>
120
- </div>
121
- <Separator className='w-[4rem] sm:w-[6rem]'/>
122
- <div className={cn('w-6 h-6 rounded-full border border-foreground flex flex-col justify-center items-center', currentStep === 3 ? 'bg-foreground text-muted-4' : '')}>
123
- 3
124
- <div className='relative text-foreground top-2 h-0 whitespace-nowrap'>Shipping info</div>
112
+ <div className='flex flex-col gap-8 sm:gap-14 col-span-5 md:col-span-3 max-w-[30rem] w-full mx-auto overflow-y-auto h-[calc(100%-40px)] sm:h-[calc(100%-48px)] py-4'>
113
+ <div className='flex gap-2 mx-auto items-center text-xxs sm:text-base'>
114
+ <div className={cn('w-6 h-6 rounded-full border border-foreground flex flex-col justify-center items-center', currentStep === 1 ? 'bg-foreground text-muted-4' : '')}>
115
+ <div className='relative text-foreground top-4 h-0 whitespace-nowrap'>Contact</div>
116
+ </div>
117
+ <Separator className='w-[4rem] sm:w-[6rem]'/>
118
+ <div className={cn('w-6 h-6 rounded-full border border-foreground flex flex-col justify-center items-center', currentStep === 2 ? 'bg-foreground text-muted-4' : '')}>
119
+ <div className='relative text-foreground top-4 h-0 whitespace-nowrap'>Payment</div>
120
+ </div>
121
+ <Separator className='w-[4rem] sm:w-[6rem]'/>
122
+ <div className={cn('w-6 h-6 rounded-full border border-foreground flex flex-col justify-center items-center', currentStep === 3 ? 'bg-foreground text-muted-4' : '')}>
123
+ <div className='relative text-foreground top-4 h-0 whitespace-nowrap'>Delivery</div>
124
+ </div>
125
125
  </div>
126
+ {steps[currentStep - 1]}
126
127
  </div>
127
- {steps[currentStep - 1]}
128
128
  </div>
129
129
  </Main>
130
130
  </div>
@@ -27,13 +27,6 @@ const InfoField: React.FC<{label: string, value: ReactNode, copyValue: string}>
27
27
 
28
28
  const PayByBankTransfer: React.FC<{setCurrentStep: (step: number) => void}> = ({setCurrentStep}) => {
29
29
  return (<>
30
- <EnhHeadingBlockComponent
31
- block={{blockType: 'enh-heading',
32
- specifiers: 'center byline-center',
33
- heading: { text: `WIRE INFO`, level: 3 },
34
- byline: { text: 'Click the copy icon to copy text to your clipboard.', level: 6}
35
- } satisfies EnhHeadingBlock as Block}
36
- />
37
30
  <Tabs defaultValue="usd" className='w-full mx-auto max-w-[50rem]'>
38
31
  <TabsList className="grid w-full grid-cols-2 max-w-[15rem] mx-auto bg-level-2">
39
32
  <TabsTrigger value="usd">USD</TabsTrigger>
@@ -28,6 +28,12 @@ import Usdt from './icons/usdt'
28
28
  import { useCommerce } from '../..'
29
29
  import { formatPrice } from '../../util'
30
30
 
31
+ declare global {
32
+ interface Window{
33
+ ethereum?: any
34
+ }
35
+ }
36
+
31
37
  const PayWithCrypto: React.FC<{
32
38
  setCurrentStep: (currentStep: number) => void
33
39
  }> = observer(({
@@ -41,10 +47,12 @@ const PayWithCrypto: React.FC<{
41
47
  const [amount, setAmount] = useState<number>()
42
48
  const [availableAmount, setAvailableAmount] = useState<number>()
43
49
  const [provider, setProvider] = useState<ethers.BrowserProvider>()
50
+ const [transactionStatus, setTransactionStatus] = useState<'unpaid' | 'paid' | 'confirmed' | 'error'>('unpaid')
44
51
 
45
52
  //const selectedToken = 'eth'
46
53
 
47
54
  useEffect(() => {
55
+ setTransactionStatus('unpaid')
48
56
  // responding to changes in user.walletAddress
49
57
  return autorun(() => {
50
58
  const newProvider = new ethers.BrowserProvider(window.ethereum)
@@ -115,7 +123,17 @@ const PayWithCrypto: React.FC<{
115
123
  })
116
124
  console.log({ ether, addr: process.env.NEXT_PUBLIC_ETH_PAYMENT_ADDRESS })
117
125
  console.log('tx', tx)
118
- setCurrentStep(3)
126
+ setTransactionStatus('paid')
127
+
128
+ provider.waitForTransaction(tx.hash)
129
+ .then((receipt) => {
130
+ console.log(receipt)
131
+ setTransactionStatus('confirmed')
132
+ })
133
+ .catch((error) => {
134
+ console.log(error)
135
+ setTransactionStatus('error')
136
+ })
119
137
  } catch (err) {
120
138
  console.log(err)
121
139
  // :aa TODO string table
@@ -149,12 +167,18 @@ const PayWithCrypto: React.FC<{
149
167
  <Input value={amount ? amount/(10**18) : amount} contentEditable={false}/>
150
168
  <div className='relative flex items-center gap-2 -top-[32px] justify-end px-2 py-1 rounded-lg bg-muted-4 w-fit text-xs float-right mr-3'><Eth height={10}/>ETH</div>
151
169
  </div>
152
- <Button
153
- onClick={() => sendPayment(amount ? amount/(10**18) : 0)}
154
- disabled={!amount || loadingPrice}
155
- >
156
- Pay now
157
- </Button>
170
+ {transactionStatus === 'unpaid' || transactionStatus === 'error' ? (
171
+ <Button
172
+ onClick={() => sendPayment(amount ? amount/(10**18) : 0)}
173
+ disabled={!amount || loadingPrice}
174
+ >
175
+ Pay now
176
+ </Button>
177
+ ) : transactionStatus === 'paid' ? (
178
+ <h4>Waiting for transaction to be confirmed on chain.</h4>
179
+ ) : (
180
+ <h4>Transaction confirmed!</h4>
181
+ )}
158
182
  </div>
159
183
  )
160
184
 
@@ -163,7 +187,7 @@ const PayWithCrypto: React.FC<{
163
187
  {payWidget}
164
188
  <div className='flex gap-4 items-center mt-6'>
165
189
  <Button variant='outline' onClick={() => setCurrentStep(1)} className='mx-auto w-full'>Back</Button>
166
- <Button onClick={() => setCurrentStep(3)} className='mx-auto w-full'>Continue (Pay later)</Button>
190
+ <Button onClick={() => setCurrentStep(3)} disabled={transactionStatus !== 'confirmed'} className='mx-auto w-full'>Continue</Button>
167
191
  </div>
168
192
  </div>
169
193
  )
@@ -66,12 +66,6 @@ const ShippingInfo: React.FC<{
66
66
  <Form {...shippingForm}>
67
67
  <form onSubmit={shippingForm.handleSubmit(onSubmit)} className='text-left'>
68
68
  <div className='flex flex-col gap-4'>
69
- <div className='flex gap-4 items-center'>
70
- <BookUser />
71
- <EnhHeadingBlockComponent block={{blockType: 'enh-heading',
72
- heading: { text: `Shipping address`, level: 4 },
73
- } as EnhHeadingBlock}/>
74
- </div>
75
69
  <div className='flex gap-4 items-end'>
76
70
  <FormField
77
71
  control={shippingForm.control}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/commerce",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "Library with shopping cart components.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",
@@ -27,11 +27,11 @@
27
27
  "clean": "rm -rf dist && rm -rf node_modules"
28
28
  },
29
29
  "dependencies": {
30
- "@hookform/resolvers": "^3.3.2",
30
+ "@hookform/resolvers": "^3.3.4",
31
31
  "ethers": "^6.11.1",
32
32
  "lucide-react": "^0.307.0",
33
33
  "next-usequerystate": "^1.17.0",
34
- "react-hook-form": "^7.51.0",
34
+ "react-hook-form": "7.50.1",
35
35
  "react-mobile-picker": "^1.0.0",
36
36
  "zod": "3.21.4"
37
37
  },