From e57d01c8553489acc218ca68ea1b80c0ee1f90df Mon Sep 17 00:00:00 2001 From: ByteZhang Date: Mon, 9 Dec 2024 18:23:42 +0800 Subject: [PATCH] Optimize: evm params (#244) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: optimize example * chore: optimize evm example * chore: optimize sui、tron、cfx example * chore: optimize sui example * chore: optimize evm example --- .github/workflows/deploy-dapp-example-web.yml | 1 + .github/workflows/publish-npm-package.yml | 1 + packages/core/src/versionInfo.ts | 2 +- packages/example/.env.simple | 4 +- packages/example/chains.ts | 6 + .../ApiActuator/ApiPayloadProvider.tsx | 2 +- .../components/ApiForm/ApiAutoTextArea.tsx | 69 + .../example/components/ApiForm/ApiButton.tsx | 114 ++ .../components/ApiForm/ApiCheckbox.tsx | 56 + .../components/ApiForm/ApiCombobox.tsx | 164 +++ .../example/components/ApiForm/ApiField.tsx | 86 ++ .../example/components/ApiForm/ApiForm.tsx | 133 ++ .../components/ApiForm/ApiJsonEdit.tsx | 70 + .../components/ApiForm/ApiSelector.tsx | 135 ++ .../components/ApiForm/ApiSeparator.tsx | 8 + .../example/components/ApiForm/ApiSwitch.tsx | 56 + .../example/components/ApiForm/ApiText.tsx | 70 + .../components/ApiForm/ApiTextArea.tsx | 72 + .../components/ApiForm/hooks/useValidation.ts | 67 + packages/example/components/ApiForm/index.ts | 51 + packages/example/components/ApiForm/store.ts | 53 + packages/example/components/ApiForm/types.ts | 20 + packages/example/components/TabCard.tsx | 42 + .../chains/aptosMartian/example.tsx | 8 +- .../components/chains/benfen/dapps.config.ts | 18 + .../components/chains/benfen/example.tsx | 380 ++++++ .../components/chains/benfen/params.ts | 37 + .../example/components/chains/benfen/types.ts | 10 + .../chains/benfen/useSignMessage.tsx | 68 + .../example/components/chains/benfen/utils.ts | 29 + .../components/chains/conflux/example.tsx | 85 ++ .../ethereum/case/contract/SampleContracts.ts | 51 + .../ethereum/case/contract/contract1155.json | 427 ++++++ .../ethereum/case/contract/contract721.json | 365 +++++ .../ethereum/case/transfer/malformed.ts | 270 ++++ .../ethereum/case/transfer/malicious.ts | 158 +++ .../components/chains/ethereum/example.tsx | 556 +++++++- .../components/chains/ethereum/utils.ts | 3 +- .../example/components/chains/nostr/params.ts | 2 +- .../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 ++ .../components/context/ContextFactory.tsx | 79 ++ packages/example/components/ui/command.tsx | 153 +++ packages/example/components/ui/tabs.tsx | 53 + packages/example/components/ui/tooltip.tsx | 28 + packages/example/package.json | 23 +- packages/example/pages/benfen/index.tsx | 16 + packages/example/yarn.lock | 1196 +++++++++++++++-- 50 files changed, 5447 insertions(+), 182 deletions(-) create mode 100644 packages/example/components/ApiForm/ApiAutoTextArea.tsx create mode 100644 packages/example/components/ApiForm/ApiButton.tsx create mode 100644 packages/example/components/ApiForm/ApiCheckbox.tsx create mode 100644 packages/example/components/ApiForm/ApiCombobox.tsx create mode 100644 packages/example/components/ApiForm/ApiField.tsx create mode 100644 packages/example/components/ApiForm/ApiForm.tsx create mode 100644 packages/example/components/ApiForm/ApiJsonEdit.tsx create mode 100644 packages/example/components/ApiForm/ApiSelector.tsx create mode 100644 packages/example/components/ApiForm/ApiSeparator.tsx create mode 100644 packages/example/components/ApiForm/ApiSwitch.tsx create mode 100644 packages/example/components/ApiForm/ApiText.tsx create mode 100644 packages/example/components/ApiForm/ApiTextArea.tsx create mode 100644 packages/example/components/ApiForm/hooks/useValidation.ts create mode 100644 packages/example/components/ApiForm/index.ts create mode 100644 packages/example/components/ApiForm/store.ts create mode 100644 packages/example/components/ApiForm/types.ts create mode 100644 packages/example/components/TabCard.tsx create mode 100644 packages/example/components/chains/benfen/dapps.config.ts create mode 100644 packages/example/components/chains/benfen/example.tsx create mode 100644 packages/example/components/chains/benfen/params.ts create mode 100644 packages/example/components/chains/benfen/types.ts create mode 100644 packages/example/components/chains/benfen/useSignMessage.tsx create mode 100644 packages/example/components/chains/benfen/utils.ts create mode 100644 packages/example/components/chains/ethereum/case/contract/SampleContracts.ts create mode 100644 packages/example/components/chains/ethereum/case/contract/contract1155.json create mode 100644 packages/example/components/chains/ethereum/case/contract/contract721.json create mode 100644 packages/example/components/chains/ethereum/case/transfer/malformed.ts create mode 100644 packages/example/components/chains/ethereum/case/transfer/malicious.ts create mode 100644 packages/example/components/chains/utils/OkLink.ts create mode 100644 packages/example/components/context/ContextFactory.tsx create mode 100644 packages/example/components/ui/command.tsx create mode 100644 packages/example/components/ui/tabs.tsx create mode 100644 packages/example/components/ui/tooltip.tsx create mode 100644 packages/example/pages/benfen/index.tsx diff --git a/.github/workflows/deploy-dapp-example-web.yml b/.github/workflows/deploy-dapp-example-web.yml index 77ea7f66..3748124b 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.EXAMPLE_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 bc2de42d..f8b98fd4 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/core/src/versionInfo.ts b/packages/core/src/versionInfo.ts index e9a21183..7510fa27 100644 --- a/packages/core/src/versionInfo.ts +++ b/packages/core/src/versionInfo.ts @@ -1,5 +1,5 @@ -const version = '2.1.20'; +const version = '2.1.21'; const versionBuild = '2020-0101-1'; export default { diff --git a/packages/example/.env.simple b/packages/example/.env.simple index da10db09..c5cc2d47 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/chains.ts b/packages/example/chains.ts index fe0aff19..56343007 100644 --- a/packages/example/chains.ts +++ b/packages/example/chains.ts @@ -67,6 +67,12 @@ export const registeredChains: IChainInfo[] = [ href: '/aptosMartian', icon: 'https://uni.onekey-asset.com/static/chain/apt.png', }, + { + id: uuid.v4(), + name: 'Benfen', + href: '/benfen', + icon: 'https://uni.onekey-asset.com/static/chain/bfc.png', + }, { id: uuid.v4(), name: 'BTC', diff --git a/packages/example/components/ApiActuator/ApiPayloadProvider.tsx b/packages/example/components/ApiActuator/ApiPayloadProvider.tsx index aeb07701..393e2e2b 100644 --- a/packages/example/components/ApiActuator/ApiPayloadProvider.tsx +++ b/packages/example/components/ApiActuator/ApiPayloadProvider.tsx @@ -18,7 +18,7 @@ type ApiPayloadAction = | { type: 'SET_PRESUPPOSE_PARAMS'; payload: IPresupposeParam[] }; // 优化 JSON 格式化函数 -const tryFormatJson = (json: string) => { +export const tryFormatJson = (json: string) => { try { return JSON.stringify(JSON.parse(json), null, 2); } catch { diff --git a/packages/example/components/ApiForm/ApiAutoTextArea.tsx b/packages/example/components/ApiForm/ApiAutoTextArea.tsx new file mode 100644 index 00000000..b5f18a01 --- /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 && ( + + )} +