|
| 1 | +import type { Meta, StoryObj } from "@storybook/react"; |
| 2 | +import { useMutation } from "@tanstack/react-query"; |
| 3 | +import { useState } from "react"; |
| 4 | +import { mobileViewport } from "../../../../../../stories/utils"; |
| 5 | +import { BluePrintPlaygroundUI } from "./BluePrintPlayground"; |
| 6 | +import type { BluePrintMetadata } from "./utils"; |
| 7 | + |
| 8 | +const meta = { |
| 9 | + title: "Insight/BluePrintPlayground", |
| 10 | + component: Story, |
| 11 | + parameters: { |
| 12 | + nextjs: { |
| 13 | + appDirectory: true, |
| 14 | + }, |
| 15 | + }, |
| 16 | +} satisfies Meta<typeof Story>; |
| 17 | + |
| 18 | +export default meta; |
| 19 | +type Story = StoryObj<typeof meta>; |
| 20 | + |
| 21 | +export const Desktop: Story = { |
| 22 | + args: { |
| 23 | + metadata: getBlueprintMetadata().transactionsMetadata, |
| 24 | + }, |
| 25 | +}; |
| 26 | + |
| 27 | +export const Mobile: Story = { |
| 28 | + args: { |
| 29 | + metadata: getBlueprintMetadata().transactionsMetadata, |
| 30 | + }, |
| 31 | + parameters: { |
| 32 | + viewport: mobileViewport("iphone14"), |
| 33 | + }, |
| 34 | +}; |
| 35 | + |
| 36 | +function Story() { |
| 37 | + return ( |
| 38 | + <div className="flex flex-col gap-10"> |
| 39 | + <Variant metadata={getBlueprintMetadata().transactionsMetadata} /> |
| 40 | + <Variant metadata={getBlueprintMetadata().eventsMetadata} /> |
| 41 | + <Variant metadata={getBlueprintMetadata().tokensMetadata} /> |
| 42 | + </div> |
| 43 | + ); |
| 44 | +} |
| 45 | + |
| 46 | +function Variant(props: { |
| 47 | + metadata: BluePrintMetadata; |
| 48 | +}) { |
| 49 | + const [response, setResponse] = useState<string | undefined>(undefined); |
| 50 | + const mutation = useMutation({ |
| 51 | + mutationFn: async () => { |
| 52 | + await new Promise((resolve) => setTimeout(resolve, 1000)); |
| 53 | + |
| 54 | + const dummyResponse = { |
| 55 | + data: { |
| 56 | + title: "This is a dummy response", |
| 57 | + content: crypto.getRandomValues(new Uint8Array(100)), |
| 58 | + }, |
| 59 | + }; |
| 60 | + |
| 61 | + return JSON.stringify(dummyResponse, null, 2); |
| 62 | + }, |
| 63 | + }); |
| 64 | + return ( |
| 65 | + <div className="flex min-h-[800px] flex-col"> |
| 66 | + <BluePrintPlaygroundUI |
| 67 | + metadata={props.metadata} |
| 68 | + backLink="/" |
| 69 | + isPending={mutation.isPending} |
| 70 | + onRun={async () => { |
| 71 | + const res = await mutation.mutateAsync(); |
| 72 | + setResponse(res); |
| 73 | + }} |
| 74 | + response={response} |
| 75 | + clientId="68665db28327c771c9a1bd5fc4580a0a" |
| 76 | + /> |
| 77 | + </div> |
| 78 | + ); |
| 79 | +} |
| 80 | + |
| 81 | +function getBlueprintMetadata() { |
| 82 | + const transactionsMetadata: BluePrintMetadata = { |
| 83 | + domain: "https://{chainId}.insight.thirdweb.com", |
| 84 | + path: "/v1/{clientId}/transactions", |
| 85 | + parameters: [ |
| 86 | + { |
| 87 | + name: "chainId", |
| 88 | + in: "path", |
| 89 | + required: true, |
| 90 | + description: "Chain ID", |
| 91 | + type: "string", |
| 92 | + }, |
| 93 | + { |
| 94 | + name: "filter", |
| 95 | + in: "query", |
| 96 | + description: "Filter parameters", |
| 97 | + type: "string", |
| 98 | + }, |
| 99 | + { |
| 100 | + name: "group_by", |
| 101 | + in: "query", |
| 102 | + description: "Field to group results by", |
| 103 | + type: "string", |
| 104 | + }, |
| 105 | + { |
| 106 | + name: "sort_by", |
| 107 | + in: "query", |
| 108 | + description: "Field to sort results by", |
| 109 | + type: "string", |
| 110 | + }, |
| 111 | + { |
| 112 | + name: "sort_order", |
| 113 | + in: "query", |
| 114 | + description: "Sort order (asc or desc)", |
| 115 | + type: "string", |
| 116 | + }, |
| 117 | + { |
| 118 | + name: "page", |
| 119 | + in: "query", |
| 120 | + description: "Page number for pagination", |
| 121 | + type: "integer", |
| 122 | + }, |
| 123 | + { |
| 124 | + name: "limit", |
| 125 | + in: "query", |
| 126 | + description: "Number of items per page", |
| 127 | + type: "integer", |
| 128 | + }, |
| 129 | + { |
| 130 | + name: "aggregate", |
| 131 | + in: "query", |
| 132 | + description: "List of aggregate functions to apply", |
| 133 | + type: "array", |
| 134 | + }, |
| 135 | + ], |
| 136 | + title: "Transactions", |
| 137 | + description: "Retrieve all transactions across all contracts", |
| 138 | + }; |
| 139 | + |
| 140 | + const eventsMetadata: BluePrintMetadata = { |
| 141 | + domain: "https://{chainId}.insight.thirdweb.com", |
| 142 | + path: "/v1/{clientId}/events", |
| 143 | + parameters: [ |
| 144 | + { |
| 145 | + name: "chainId", |
| 146 | + in: "path", |
| 147 | + required: true, |
| 148 | + description: "Chain ID", |
| 149 | + type: "string", |
| 150 | + }, |
| 151 | + { |
| 152 | + name: "filter", |
| 153 | + in: "query", |
| 154 | + description: "Filter parameters", |
| 155 | + type: "string", |
| 156 | + }, |
| 157 | + { |
| 158 | + name: "group_by", |
| 159 | + in: "query", |
| 160 | + description: "Field to group results by", |
| 161 | + type: "string", |
| 162 | + }, |
| 163 | + { |
| 164 | + name: "sort_by", |
| 165 | + in: "query", |
| 166 | + description: "Field to sort results by", |
| 167 | + type: "string", |
| 168 | + }, |
| 169 | + { |
| 170 | + name: "sort_order", |
| 171 | + in: "query", |
| 172 | + description: "Sort order (asc or desc)", |
| 173 | + type: "string", |
| 174 | + }, |
| 175 | + { |
| 176 | + name: "page", |
| 177 | + in: "query", |
| 178 | + description: "Page number for pagination", |
| 179 | + type: "integer", |
| 180 | + }, |
| 181 | + { |
| 182 | + name: "limit", |
| 183 | + in: "query", |
| 184 | + description: "Number of items per page", |
| 185 | + type: "integer", |
| 186 | + }, |
| 187 | + { |
| 188 | + name: "aggregate", |
| 189 | + in: "query", |
| 190 | + description: "List of aggregate functions to apply", |
| 191 | + type: "array", |
| 192 | + }, |
| 193 | + ], |
| 194 | + title: "Events", |
| 195 | + description: "Retrieve all logs across all contracts", |
| 196 | + }; |
| 197 | + |
| 198 | + const tokensMetadata: BluePrintMetadata = { |
| 199 | + domain: "https://{chainId}.insight.thirdweb.com", |
| 200 | + path: "/v1/{clientId}/tokens/erc20/:ownerAddress", |
| 201 | + parameters: [ |
| 202 | + { |
| 203 | + name: "ownerAddress", |
| 204 | + in: "path", |
| 205 | + required: true, |
| 206 | + type: "string", |
| 207 | + }, |
| 208 | + { |
| 209 | + name: "clientId", |
| 210 | + in: "path", |
| 211 | + required: false, |
| 212 | + type: "string", |
| 213 | + }, |
| 214 | + ], |
| 215 | + title: "Tokens", |
| 216 | + description: "Retrieve tokens balances for a given owner address", |
| 217 | + }; |
| 218 | + |
| 219 | + return { |
| 220 | + transactionsMetadata, |
| 221 | + eventsMetadata, |
| 222 | + tokensMetadata, |
| 223 | + }; |
| 224 | +} |
0 commit comments