@b3dotfun/sdk 0.0.44-alpha.0 → 0.0.44-alpha.2

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.
Files changed (42) hide show
  1. package/dist/cjs/anyspend/react/components/AnySpend.js +12 -13
  2. package/dist/cjs/anyspend/react/components/AnyspendDepositHype.js +13 -14
  3. package/dist/cjs/anyspend/react/components/common/OrderDetails.js +1 -6
  4. package/dist/cjs/anyspend/react/components/common/OrderHistory.js +2 -2
  5. package/dist/cjs/anyspend/react/components/common/OrderHistoryItem.js +7 -9
  6. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  7. package/dist/cjs/anyspend/react/hooks/useAnyspendFlow.js +3 -3
  8. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  9. package/dist/cjs/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
  10. package/dist/cjs/anyspend/types/api.d.ts +189 -10
  11. package/dist/cjs/anyspend/utils/orderPayload.js +0 -4
  12. package/dist/esm/anyspend/react/components/AnySpend.js +13 -14
  13. package/dist/esm/anyspend/react/components/AnyspendDepositHype.js +14 -15
  14. package/dist/esm/anyspend/react/components/common/OrderDetails.js +1 -6
  15. package/dist/esm/anyspend/react/components/common/OrderHistory.js +2 -2
  16. package/dist/esm/anyspend/react/components/common/OrderHistoryItem.js +9 -11
  17. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  18. package/dist/esm/anyspend/react/hooks/useAnyspendFlow.js +3 -3
  19. package/dist/esm/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  20. package/dist/esm/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
  21. package/dist/esm/anyspend/types/api.d.ts +189 -10
  22. package/dist/esm/anyspend/utils/orderPayload.js +0 -4
  23. package/dist/styles/index.css +1 -1
  24. package/dist/types/anyspend/react/hooks/useAnyspendFlow.d.ts +1 -0
  25. package/dist/types/anyspend/react/hooks/useAnyspendOrderAndTransactions.d.ts +2 -0
  26. package/dist/types/anyspend/react/hooks/useAnyspendOrderHistory.d.ts +36 -0
  27. package/dist/types/anyspend/types/api.d.ts +189 -10
  28. package/package.json +2 -1
  29. package/src/anyspend/react/components/AnySpend.tsx +20 -18
  30. package/src/anyspend/react/components/AnyspendDepositHype.tsx +21 -20
  31. package/src/anyspend/react/components/common/OrderDetails.tsx +1 -7
  32. package/src/anyspend/react/components/common/OrderHistory.tsx +11 -11
  33. package/src/anyspend/react/components/common/OrderHistoryItem.tsx +105 -137
  34. package/src/anyspend/react/hooks/useAnyspendFlow.ts +3 -3
  35. package/src/anyspend/types/api.ts +189 -10
  36. package/src/anyspend/utils/orderPayload.ts +0 -4
  37. package/dist/cjs/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  38. package/dist/cjs/anyspend/react/components/common/ErrorSection.js +0 -12
  39. package/dist/esm/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  40. package/dist/esm/anyspend/react/components/common/ErrorSection.js +0 -9
  41. package/dist/types/anyspend/react/components/common/ErrorSection.d.ts +0 -6
  42. package/src/anyspend/react/components/common/ErrorSection.tsx +0 -21
@@ -17,37 +17,37 @@ export function OrderHistory({ mode, onBack, onSelectOrder }: OrderHistoryProps)
17
17
 
18
18
  return (
19
19
  <>
20
- <div className="mb-6 flex w-full items-center gap-4">
21
- <Button onClick={onBack} variant="ghost" size="icon">
22
- <ArrowLeft className="h-4 w-4" />
20
+ <div className="mb-8 flex w-full items-center gap-3">
21
+ <Button onClick={onBack} variant="ghost" size="icon" className="hover:bg-as-surface-secondary">
22
+ <ArrowLeft className="h-5 w-5" />
23
23
  </Button>
24
24
  <div className="flex-1">
25
- <h3 className="text-xl font-semibold">Order History</h3>
26
- <p className="text-as-primary/30 text-sm">View your past transactions</p>
25
+ <h3 className="text-as-primary text-2xl font-bold">Order History</h3>
27
26
  </div>
28
27
  <Button
29
28
  variant="ghost"
30
29
  size="icon"
30
+ className="hover:bg-as-surface-secondary"
31
31
  onClick={() => {
32
32
  refetchOrderHistory();
33
33
  }}
34
34
  >
35
- <RefreshCcw className="text-as-primary/30 hover:text-as-primary h-4 w-4 cursor-pointer transition-all hover:rotate-180" />
35
+ <RefreshCcw className="text-as-secondary hover:text-as-primary h-5 w-5 cursor-pointer transition-all hover:rotate-180" />
36
36
  </Button>
37
37
  </div>
38
38
 
39
39
  {isLoadingOrderHistory ? (
40
- <div className="w-full space-y-4">
40
+ <div className="w-full space-y-3">
41
41
  {[1, 2, 3].map(i => (
42
- <Skeleton key={i} className="h-[160px] w-full rounded-lg" />
42
+ <Skeleton key={i} className="h-[180px] w-full rounded-2xl" />
43
43
  ))}
44
44
  </div>
45
45
  ) : !orderHistory?.length ? (
46
- <div className="bg-as-light-brand w-full rounded-lg border p-8 text-center">
47
- <p className="text-b3-react-muted-foreground">No order history found</p>
46
+ <div className="bg-as-surface-secondary w-full rounded-2xl p-12 text-center">
47
+ <p className="text-as-secondary text-sm">No order history found</p>
48
48
  </div>
49
49
  ) : (
50
- <div className="mb-12 w-full space-y-4">
50
+ <div className="mb-12 w-full space-y-3">
51
51
  {[...orderHistory]
52
52
  .sort((a, b) => b.createdAt - a.createdAt)
53
53
  .map(order => (
@@ -2,6 +2,7 @@ import { ALL_CHAINS, getChainName, getStatusDisplay } from "@b3dotfun/sdk/anyspe
2
2
  import { Badge, Button, useIsMobile } from "@b3dotfun/sdk/global-account/react";
3
3
  import { cn } from "@b3dotfun/sdk/shared/utils";
4
4
  import { formatTokenAmount } from "@b3dotfun/sdk/shared/utils/number";
5
+ import { getVendorDisplayName } from "@b3dotfun/sdk/shared/utils/payment.utils";
5
6
  import { ArrowRight, ChevronDown } from "lucide-react";
6
7
  import TimeAgo from "react-timeago";
7
8
  import { b3 } from "viem/chains";
@@ -18,13 +19,7 @@ export function OrderHistoryItem({ order, onSelectOrder, mode }: OrderHistoryIte
18
19
  const tournament =
19
20
  order.type === "join_tournament" || order.type === "fund_tournament" ? order.metadata.tournament : undefined;
20
21
  const dstToken = order.metadata.dstToken;
21
- const actualDstAmount =
22
- order.type === "mint_nft" ||
23
- order.type === "join_tournament" ||
24
- order.type === "fund_tournament" ||
25
- order.type === "custom"
26
- ? undefined
27
- : order.payload.actualDstAmount;
22
+ const actualDstAmount = order.settlement?.actualDstAmount;
28
23
  const expectedDstAmount =
29
24
  order.type === "mint_nft" ||
30
25
  order.type === "join_tournament" ||
@@ -37,153 +32,126 @@ export function OrderHistoryItem({ order, onSelectOrder, mode }: OrderHistoryIte
37
32
 
38
33
  const isSmallView = useIsMobile() || mode === "modal";
39
34
 
35
+ // Check if this is a one-click payment order
36
+ const isOneClickPayment = !!order.oneClickBuyUrl;
37
+ const vendorName = order.onrampMetadata?.vendor ? getVendorDisplayName(order.onrampMetadata.vendor) : null;
38
+
40
39
  return (
41
40
  <div
42
41
  key={`anyspend-${order.id}`}
43
42
  className={cn(
44
- "bg-as-light-brand/20 rounded-lg border p-4",
45
- onSelectOrder && "hover:bg-as-light-brand/30 hover:border-as-brand cursor-pointer transition-colors",
43
+ "bg-as-surface-secondary hover:bg-as-surface-tertiary rounded-xl p-4 transition-all",
44
+ onSelectOrder && "cursor-pointer",
46
45
  )}
47
46
  onClick={() => onSelectOrder?.(order.id)}
48
47
  >
49
- <div className="flex items-center justify-between">
50
- <Badge
51
- className={cn(
52
- "px-3 py-1 text-xs",
53
- orderDisplayStatus === "processing" && "bg-yellow-500/10 text-yellow-500",
54
- orderDisplayStatus === "success" && "bg-green-500/10 text-green-500",
55
- orderDisplayStatus === "failure" && "bg-red-500/10 text-red-500",
56
- )}
57
- >
58
- {orderStatusText}
59
- </Badge>
60
-
48
+ {/* Header: Status and Time */}
49
+ <div className="mb-3 flex items-center justify-between">
61
50
  <div className="flex items-center gap-2">
62
- <span className="text-nano label-style text-as-primary/30">
63
- <TimeAgo date={new Date(order.createdAt)} />
64
- </span>
51
+ <div
52
+ className={cn(
53
+ "text-xs font-semibold",
54
+ orderDisplayStatus === "processing" && "text-yellow-600",
55
+ orderDisplayStatus === "success" && "text-green-600",
56
+ orderDisplayStatus === "failure" && "text-red-600",
57
+ )}
58
+ >
59
+ {orderStatusText}
60
+ </div>
61
+ {isOneClickPayment && vendorName && (
62
+ <Badge variant="outline" className="text-as-secondary px-2 py-0.5 text-[10px]">
63
+ {vendorName}
64
+ </Badge>
65
+ )}
66
+ </div>
67
+ <div className="text-as-secondary text-[10px] font-medium uppercase tracking-wide">
68
+ <TimeAgo date={new Date(order.createdAt)} />
65
69
  </div>
66
70
  </div>
67
71
 
68
- {order.oneClickBuyUrl ? (
69
- <div className="mb-3 mt-4 flex items-center gap-1">
70
- <div className="bg-b3-react-background flex flex-1 flex-col gap-1 rounded-lg border p-4 px-5">
71
- <h3 className="text-as-primary/50 flex items-center gap-2 text-xl font-semibold">
72
- <span>
73
- {"Buy "}
74
- <span className="text-as-primary">
75
- ${formatTokenAmount(BigInt(order.srcAmount), order.metadata.srcToken.decimals)}
76
- </span>
77
- {` of`}
78
- </span>
79
-
80
- <span className="text-as-primary flex items-center gap-2">
81
- {nft ? (
82
- <img src={nft.imageUrl} alt={nft.name} className="h-6 w-6" />
83
- ) : tournament ? (
84
- <img src={tournament.imageUrl} alt={tournament.name} className="h-6 w-6" />
85
- ) : (
86
- <img src={dstToken.metadata.logoURI} alt={dstToken.symbol} className="h-6 w-6" />
87
- )}
88
- {nft ? nft.name : tournament ? tournament.name : dstToken.symbol}
89
- </span>
90
-
91
- <span className="flex items-center gap-2">
92
- {` on `}
93
- <span className="text-as-primary flex items-center gap-2">
94
- <img src={ALL_CHAINS[order.dstChain]?.logoUrl} alt={getChainName(order.dstChain)} className="h-4" />
95
- {order.dstChain !== b3.id && getChainName(order.dstChain)}
96
- </span>
97
- </span>
98
- </h3>
99
-
100
- <p className="label-style text-as-primary/30 mt-1 flex items-center gap-2 text-xs">
101
- Paying via{" "}
102
- <img src="https://cdn.b3.fun/coinbase-wordmark-blue.svg" alt="Coinbase" className="-mt-1 h-3" />
103
- </p>
104
- </div>
105
- </div>
106
- ) : (
107
- <div className={cn("mb-3 mt-4 flex items-center gap-1", isSmallView && "flex-col")}>
108
- <div className="bg-b3-react-background flex w-full flex-1 flex-col gap-1 overflow-hidden rounded-lg border p-4 px-5">
109
- <div className="flex items-center gap-2">
110
- <img
111
- src={order.metadata.srcToken.metadata.logoURI}
112
- alt={order.metadata.srcToken.symbol}
113
- className="h-6 w-6 rounded-full"
114
- />
115
- <div className="text-as-primary flex items-center gap-2 overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold">
116
- {formatTokenAmount(BigInt(order.srcAmount), order.metadata.srcToken.decimals)}{" "}
117
- {order.metadata.srcToken.symbol}
118
- </div>
72
+ {/* Main Content: From -> To */}
73
+ <div className="flex items-center gap-4">
74
+ {/* From Section */}
75
+ <div className="flex min-w-0 flex-1 items-center gap-2">
76
+ <img
77
+ src={order.metadata.srcToken.metadata.logoURI}
78
+ alt={order.metadata.srcToken.symbol}
79
+ className="h-8 w-8 shrink-0 rounded-full"
80
+ />
81
+ <div className="min-w-0 flex-1">
82
+ <div className="text-as-primary truncate text-sm font-bold">
83
+ {formatTokenAmount(BigInt(order.srcAmount), order.metadata.srcToken.decimals)}{" "}
84
+ {order.metadata.srcToken.symbol}
119
85
  </div>
120
-
121
- <div className="label-style text-as-primary/50 flex items-center gap-2 text-sm">
122
- from
123
- <img
124
- src={ALL_CHAINS[order.srcChain]?.logoUrl}
125
- alt={getChainName(order.srcChain)}
126
- className={cn("h-4", order.srcChain !== b3.id && "w-4 rounded-full", order.srcChain === b3.id && "h-3")}
127
- />
128
- {getChainName(order.srcChain)}
86
+ <div className="text-as-secondary flex items-center gap-1 text-xs">
87
+ <img src={ALL_CHAINS[order.srcChain]?.logoUrl} alt={getChainName(order.srcChain)} className="h-3 w-3" />
88
+ <span className="truncate">{getChainName(order.srcChain)}</span>
129
89
  </div>
130
90
  </div>
91
+ </div>
131
92
 
132
- <div className={cn("h-8 w-8 shrink-0 -rotate-90 opacity-30", isSmallView && "rotate-0")}>
133
- <ChevronDown className="h-8 w-8" />
134
- </div>
93
+ {/* Arrow */}
94
+ <ArrowRight className="text-as-secondary h-5 w-5 shrink-0 opacity-30" />
135
95
 
136
- <div className="bg-b3-react-background flex w-full flex-1 flex-col gap-1 overflow-hidden rounded-lg border p-4 px-5">
137
- <div className="flex items-center gap-2">
138
- {nft ? (
139
- <>
140
- <img src={nft.imageUrl} alt={nft.name} className="h-6 w-6 rounded-full" />
141
- <div className="text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold">
142
- {nft.name}
143
- </div>
144
- </>
145
- ) : tournament ? (
146
- <>
147
- <img src={tournament.imageUrl} alt={tournament.name} className="h-6 w-6 rounded-full" />
148
- <div className="text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold">
149
- {tournament.name}
150
- </div>
151
- </>
152
- ) : (
153
- <>
154
- <img src={dstToken.metadata.logoURI} alt={dstToken.symbol} className="h-6 w-6 rounded-full" />
155
- <div className="text-as-primary overflow-hidden text-ellipsis whitespace-nowrap text-xl font-semibold">
156
- {formatTokenAmount(
157
- actualDstAmount
158
- ? BigInt(actualDstAmount)
159
- : expectedDstAmount
160
- ? BigInt(expectedDstAmount)
161
- : BigInt(0),
162
- dstToken.decimals,
163
- )}{" "}
164
- {dstToken.symbol}
165
- </div>
166
- </>
167
- )}
168
- </div>
169
- <div className="label-style text-as-primary/50 flex items-center gap-2 text-sm">
170
- to
171
- <img
172
- src={ALL_CHAINS[order.dstChain]?.logoUrl}
173
- alt={getChainName(order.dstChain)}
174
- className={cn("h-4", order.dstChain !== b3.id && "w-4 rounded-full", order.dstChain === b3.id && "h-3")}
175
- />
176
- {getChainName(order.dstChain)}
177
- </div>
178
- </div>
96
+ {/* To Section */}
97
+ <div className="flex min-w-0 flex-1 items-center gap-2">
98
+ {nft ? (
99
+ <>
100
+ <img src={nft.imageUrl} alt={nft.name} className="h-8 w-8 shrink-0 rounded-full" />
101
+ <div className="min-w-0 flex-1">
102
+ <div className="text-as-primary truncate text-sm font-bold">{nft.name}</div>
103
+ <div className="text-as-secondary flex items-center gap-1 text-xs">
104
+ <img
105
+ src={ALL_CHAINS[order.dstChain]?.logoUrl}
106
+ alt={getChainName(order.dstChain)}
107
+ className="h-3 w-3"
108
+ />
109
+ <span className="truncate">{getChainName(order.dstChain)}</span>
110
+ </div>
111
+ </div>
112
+ </>
113
+ ) : tournament ? (
114
+ <>
115
+ <img src={tournament.imageUrl} alt={tournament.name} className="h-8 w-8 shrink-0 rounded-full" />
116
+ <div className="min-w-0 flex-1">
117
+ <div className="text-as-primary truncate text-sm font-bold">{tournament.name}</div>
118
+ <div className="text-as-secondary flex items-center gap-1 text-xs">
119
+ <img
120
+ src={ALL_CHAINS[order.dstChain]?.logoUrl}
121
+ alt={getChainName(order.dstChain)}
122
+ className="h-3 w-3"
123
+ />
124
+ <span className="truncate">{getChainName(order.dstChain)}</span>
125
+ </div>
126
+ </div>
127
+ </>
128
+ ) : (
129
+ <>
130
+ <img src={dstToken.metadata.logoURI} alt={dstToken.symbol} className="h-8 w-8 shrink-0 rounded-full" />
131
+ <div className="min-w-0 flex-1">
132
+ <div className="text-as-primary truncate text-sm font-bold">
133
+ {formatTokenAmount(
134
+ actualDstAmount
135
+ ? BigInt(actualDstAmount)
136
+ : expectedDstAmount
137
+ ? BigInt(expectedDstAmount)
138
+ : BigInt(0),
139
+ dstToken.decimals,
140
+ )}{" "}
141
+ {dstToken.symbol}
142
+ </div>
143
+ <div className="text-as-secondary flex items-center gap-1 text-xs">
144
+ <img
145
+ src={ALL_CHAINS[order.dstChain]?.logoUrl}
146
+ alt={getChainName(order.dstChain)}
147
+ className="h-3 w-3"
148
+ />
149
+ <span className="truncate">{getChainName(order.dstChain)}</span>
150
+ </div>
151
+ </div>
152
+ </>
153
+ )}
179
154
  </div>
180
- )}
181
-
182
- <div className="flex items-center justify-end">
183
- <Button variant="link" size="sm" className="h-auto" onClick={() => onSelectOrder?.(order.id)}>
184
- {orderDisplayStatus === "processing" ? "Proceed with payment" : "Details"}{" "}
185
- <ArrowRight className="ml-2 h-3 w-3" />
186
- </Button>
187
155
  </div>
188
156
  </div>
189
157
  );
@@ -247,8 +247,8 @@ export function useAnyspendFlow({
247
247
  // Handle order completion
248
248
  useEffect(() => {
249
249
  if (oat?.data?.order.status === "executed") {
250
- // get the actualDstAmount if available from custompayload
251
- const amount = (oat.data.order.payload as { actualDstAmount?: string })?.actualDstAmount;
250
+ // get the actualDstAmount if available from settlement
251
+ const amount = oat.data.order.settlement?.actualDstAmount;
252
252
  const formattedActualDstAmount = amount
253
253
  ? formatTokenAmount(BigInt(amount), oat.data.order.metadata.dstToken.decimals)
254
254
  : undefined;
@@ -256,7 +256,7 @@ export function useAnyspendFlow({
256
256
  }
257
257
  }, [
258
258
  oat?.data?.order.status,
259
- oat?.data?.order.payload,
259
+ oat?.data?.order.settlement?.actualDstAmount,
260
260
  onTransactionSuccess,
261
261
  oat?.data?.order.metadata.dstToken.decimals,
262
262
  ]);