From 146369b1f116bc40d2d022ccf0775052b8e65a7d Mon Sep 17 00:00:00 2001 From: drafish Date: Sat, 6 Jul 2024 14:39:47 +0800 Subject: [PATCH] fallback and receive for quick-dapp --- apps/quick-dapp/src/actions/index.ts | 26 +++++++++++++++++++++++ apps/quick-dapp/src/remix-client.ts | 3 ++- libs/remix-ui/run-tab/src/lib/run-tab.tsx | 8 ++++--- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/apps/quick-dapp/src/actions/index.ts b/apps/quick-dapp/src/actions/index.ts index d0fa157f6d..fa90328401 100644 --- a/apps/quick-dapp/src/actions/index.ts +++ b/apps/quick-dapp/src/actions/index.ts @@ -1,5 +1,6 @@ import axios from 'axios'; import { omitBy } from 'lodash'; +import semver from 'semver'; import { execution } from '@remix-project/remix-lib'; import SurgeClient from '@drafish/surge-client'; import remixClient from '../remix-client'; @@ -16,6 +17,21 @@ const surgeClient = new SurgeClient({ }, }); +const getVersion = (solcVersion) => { + let version = '0.8.25' + try { + const arr = solcVersion.split('+') + if (arr && arr[0]) version = arr[0] + if (semver.lt(version, '0.6.0')) { + return { version: version, canReceive: false }; + } else { + return { version: version, canReceive: true }; + } + } catch (e) { + return { version, canReceive: true }; + } +}; + let dispatch: any, state: any; export const initDispatch = (_dispatch: any) => { @@ -221,6 +237,7 @@ export const deploy = async (payload: any, callback: any) => { export const initInstance = async ({ methodIdentifiers, devdoc, + solcVersion, ...payload }: any) => { const functionHashes: any = {}; @@ -257,11 +274,18 @@ export const initInstance = async ({ } const abi: any = {}; + const lowLevel: any = {} payload.abi.forEach((item: any) => { if (item.type === 'function') { item.id = encodeFunctionId(item); abi[item.id] = item; } + if (item.type === 'fallback') { + lowLevel.fallback = item; + } + if (item.type === 'receive') { + lowLevel.receive = item; + } }); const ids = Object.keys(abi); const items = @@ -279,6 +303,8 @@ export const initInstance = async ({ items, containers: Object.keys(items), natSpec, + solcVersion: getVersion(solcVersion), + ...lowLevel, }, }); }; diff --git a/apps/quick-dapp/src/remix-client.ts b/apps/quick-dapp/src/remix-client.ts index 9687dee67c..1f213f0a77 100644 --- a/apps/quick-dapp/src/remix-client.ts +++ b/apps/quick-dapp/src/remix-client.ts @@ -8,7 +8,7 @@ class RemixClient extends PluginClient { createClient(this); } - edit({ address, abi, network, name, devdoc, methodIdentifiers }: any): void { + edit({ address, abi, network, name, devdoc, methodIdentifiers, solcVersion }: any): void { initInstance({ address, abi, @@ -16,6 +16,7 @@ class RemixClient extends PluginClient { name, devdoc, methodIdentifiers, + solcVersion, }); } } diff --git a/libs/remix-ui/run-tab/src/lib/run-tab.tsx b/libs/remix-ui/run-tab/src/lib/run-tab.tsx index 42fd41490d..403c13b24b 100644 --- a/libs/remix-ui/run-tab/src/lib/run-tab.tsx +++ b/libs/remix-ui/run-tab/src/lib/run-tab.tsx @@ -356,13 +356,15 @@ export function RunTabUI(props: RunTabProps) { getFuncABIInputs={getFuncABIValues} exEnvironment={runTab.selectExEnv} editInstance={(instance) => { + const { metadata, abi, object } = instance.contractData; plugin.call('quick-dapp', 'edit', { address: instance.address, - abi: instance.contractData.abi, + abi: abi, name: instance.name, network: runTab.networkName, - devdoc: instance.contractData.object.devdoc, - methodIdentifiers: instance.contractData.object.evm.methodIdentifiers, + devdoc: object.devdoc, + methodIdentifiers: object.evm.methodIdentifiers, + solcVersion: JSON.parse(metadata).compiler.version, }) }} />