From 6c77d0540e07b66441ced03d01800f1481fd8473 Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Wed, 6 Nov 2024 09:25:41 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20optimize=20sui=E3=80=81tron=E3=80=81cf?= =?UTF-8?q?x=20example?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy-dapp-example-web.yml | 1 + .github/workflows/publish-npm-package.yml | 1 + packages/example/.env.simple | 4 +- .../components/ApiForm/ApiAutoTextArea.tsx | 69 +++ .../example/components/ApiForm/ApiButton.tsx | 39 +- .../components/ApiForm/ApiCheckbox.tsx | 4 + .../components/ApiForm/ApiCombobox.tsx | 15 +- .../example/components/ApiForm/ApiField.tsx | 11 +- .../components/ApiForm/ApiJsonEdit.tsx | 13 +- .../components/ApiForm/ApiSelector.tsx | 25 +- .../example/components/ApiForm/ApiSwitch.tsx | 4 + .../example/components/ApiForm/ApiText.tsx | 70 +++ .../components/ApiForm/ApiTextArea.tsx | 18 +- packages/example/components/ApiForm/index.ts | 10 +- packages/example/components/ApiForm/store.ts | 6 - packages/example/components/ApiForm/types.ts | 5 +- packages/example/components/TabCard.tsx | 42 ++ .../components/chains/conflux/example.tsx | 85 +++ .../components/chains/ethereum/example.tsx | 493 ++++++++---------- .../components/chains/suiStandard/example.tsx | 161 +++++- .../components/chains/suiStandard/utils.ts | 4 +- .../components/chains/tron/example.tsx | 91 +++- .../example/components/chains/utils/OkLink.ts | 76 +++ packages/example/components/ui/tooltip.tsx | 28 + packages/example/package.json | 1 + packages/example/yarn.lock | 18 + 26 files changed, 978 insertions(+), 316 deletions(-) create mode 100644 packages/example/components/ApiForm/ApiAutoTextArea.tsx create mode 100644 packages/example/components/ApiForm/ApiText.tsx create mode 100644 packages/example/components/TabCard.tsx create mode 100644 packages/example/components/chains/utils/OkLink.ts create mode 100644 packages/example/components/ui/tooltip.tsx diff --git a/.github/workflows/deploy-dapp-example-web.yml b/.github/workflows/deploy-dapp-example-web.yml index 77ea7f66c..219efa87e 100644 --- a/.github/workflows/deploy-dapp-example-web.yml +++ b/.github/workflows/deploy-dapp-example-web.yml @@ -25,6 +25,7 @@ jobs: # Next.js environment variables echo "NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=${{ secrets.WALLET_CONNECT_PROJECT_ID }}" > ./packages/example/.env echo "NEXT_PUBLIC_BLOCKFROST_CARDANO_PROJECT_ID=${{ secrets.BLOCKFROST_CARDANO_PROJECT_ID }}" >> ./packages/example/.env + echo "NEXT_PUBLIC_OKLINK_API_KEY=${{ secrets.OKLINK_API_KEY }}" >> ./packages/example/.env - name: Install Dependency env: diff --git a/.github/workflows/publish-npm-package.yml b/.github/workflows/publish-npm-package.yml index bc2de42d6..f8b98fd46 100644 --- a/.github/workflows/publish-npm-package.yml +++ b/.github/workflows/publish-npm-package.yml @@ -47,6 +47,7 @@ jobs: # Next.js environment variables echo "NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=${{ secrets.WALLET_CONNECT_PROJECT_ID }}" > ./packages/example/.env echo "NEXT_PUBLIC_BLOCKFROST_CARDANO_PROJECT_ID=${{ secrets.BLOCKFROST_CARDANO_PROJECT_ID }}" >> ./packages/example/.env + echo "NEXT_PUBLIC_OKLINK_API_KEY=${{ secrets.OKLINK_API_KEY }}" >> ./packages/example/.env - name: Build Example Web run: | diff --git a/packages/example/.env.simple b/packages/example/.env.simple index da10db091..c5cc2d476 100644 --- a/packages/example/.env.simple +++ b/packages/example/.env.simple @@ -2,4 +2,6 @@ NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID=xxxx NEXT_PUBLIC_WALLET_CONNECT_RELAY_URL=wss://relay.walletconnect.com # block frost project id -NEXT_PUBLIC_BLOCKFROST_CARDANO_PROJECT_ID=xxxx \ No newline at end of file +NEXT_PUBLIC_BLOCKFROST_CARDANO_PROJECT_ID=xxxx +# oklink api key +NEXT_PUBLIC_OKLINK_API_KEY=xxxx diff --git a/packages/example/components/ApiForm/ApiAutoTextArea.tsx b/packages/example/components/ApiForm/ApiAutoTextArea.tsx new file mode 100644 index 000000000..b5f18a01d --- /dev/null +++ b/packages/example/components/ApiForm/ApiAutoTextArea.tsx @@ -0,0 +1,69 @@ +import React, { memo, useContext, useEffect } from 'react'; +import { useAtom } from 'jotai'; +import { Label } from '../ui/label'; +import { ApiFormContext } from './ApiForm'; +import { AutoHeightTextarea } from '../ui/textarea'; + + +interface AutoTextAreaProps { + id: string; + placeholder?: string; + label?: string; + required?: boolean; +} + +const TextArea = memo(({ + id, + placeholder, + label, + required +}: AutoTextAreaProps) => { + const context = useContext(ApiFormContext); + if (!context) throw new Error('ApiField must be used within ApiForm'); + + const { store } = context; + const [field, setField] = useAtom(store.fieldsAtom(id)); + + useEffect(() => { + field.name = label; + field.required = required; + }, []); + + return <> + setField({ ...field, value: e.target.value })} + placeholder={placeholder} + disabled={field.disabled} + /> + {field.error && ( +
{field.error}
+ )} + +}); + +export interface ApiAutoTextAreaProps extends AutoTextAreaProps { + id: string; +} + +export const ApiAutoTextArea = memo(({ + id, + label, + placeholder, + required +}: ApiAutoTextAreaProps) => { + return ( +
+ {label && ( + + )} +