@openzeppelin/ui-builder-adapter-evm 0.15.1 → 1.0.0
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.
- package/dist/index.cjs +61 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +65 -3
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/adapter.ts +8 -0
- package/src/configuration/rpc.ts +48 -0
- package/src/mapping/__tests__/field-generator.test.ts +37 -0
- package/src/mapping/field-generator.ts +32 -3
package/dist/index.cjs
CHANGED
|
@@ -1072,6 +1072,41 @@ async function testEvmRpcConnection(rpcConfig, timeoutMs = 5e3) {
|
|
|
1072
1072
|
clearTimeout(timeoutId);
|
|
1073
1073
|
}
|
|
1074
1074
|
}
|
|
1075
|
+
async function getEvmCurrentBlock(networkConfig) {
|
|
1076
|
+
const rpcUrl = resolveRpcUrl(networkConfig);
|
|
1077
|
+
try {
|
|
1078
|
+
const response = await fetch(rpcUrl, {
|
|
1079
|
+
method: "POST",
|
|
1080
|
+
headers: { "Content-Type": "application/json" },
|
|
1081
|
+
body: JSON.stringify({
|
|
1082
|
+
jsonrpc: "2.0",
|
|
1083
|
+
method: "eth_blockNumber",
|
|
1084
|
+
params: [],
|
|
1085
|
+
id: 1
|
|
1086
|
+
})
|
|
1087
|
+
});
|
|
1088
|
+
if (!response.ok) {
|
|
1089
|
+
throw new Error(`RPC request failed with status ${response.status}`);
|
|
1090
|
+
}
|
|
1091
|
+
const data = await response.json();
|
|
1092
|
+
if (data.error) {
|
|
1093
|
+
throw new Error(data.error.message || "RPC error");
|
|
1094
|
+
}
|
|
1095
|
+
if (data.result === void 0 || data.result === null) {
|
|
1096
|
+
throw new Error("RPC response missing result field");
|
|
1097
|
+
}
|
|
1098
|
+
const blockNumber = parseInt(data.result, 16);
|
|
1099
|
+
if (isNaN(blockNumber)) {
|
|
1100
|
+
throw new Error(`Invalid block number returned: ${data.result}`);
|
|
1101
|
+
}
|
|
1102
|
+
return blockNumber;
|
|
1103
|
+
} catch (error) {
|
|
1104
|
+
import_ui_builder_utils5.logger.error("getEvmCurrentBlock", "Failed to get current block:", error);
|
|
1105
|
+
throw new Error(
|
|
1106
|
+
`Failed to get current block: ${error instanceof Error ? error.message : String(error)}`
|
|
1107
|
+
);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1075
1110
|
|
|
1076
1111
|
// src/configuration/network-services.ts
|
|
1077
1112
|
function getEvmNetworkServiceForms(networkConfig) {
|
|
@@ -4254,6 +4289,16 @@ function extractArrayElementType(parameterType) {
|
|
|
4254
4289
|
function getDefaultValidation() {
|
|
4255
4290
|
return { required: true };
|
|
4256
4291
|
}
|
|
4292
|
+
var EVM_NUMERIC_BOUNDS = {
|
|
4293
|
+
uint: { min: 0 },
|
|
4294
|
+
uint8: { min: 0, max: 255 },
|
|
4295
|
+
uint16: { min: 0, max: 65535 },
|
|
4296
|
+
uint32: { min: 0, max: 4294967295 },
|
|
4297
|
+
int: {},
|
|
4298
|
+
int8: { min: -128, max: 127 },
|
|
4299
|
+
int16: { min: -32768, max: 32767 },
|
|
4300
|
+
int32: { min: -2147483648, max: 2147483647 }
|
|
4301
|
+
};
|
|
4257
4302
|
function generateEvmDefaultField(parameter) {
|
|
4258
4303
|
const fieldType = mapEvmParamTypeToFieldType(parameter.type);
|
|
4259
4304
|
const baseField = {
|
|
@@ -4265,7 +4310,11 @@ function generateEvmDefaultField(parameter) {
|
|
|
4265
4310
|
placeholder: `Enter ${parameter.displayName || parameter.name || parameter.type}`,
|
|
4266
4311
|
helperText: parameter.description || "",
|
|
4267
4312
|
defaultValue: (0, import_ui_builder_utils30.getDefaultValueForType)(fieldType),
|
|
4268
|
-
validation:
|
|
4313
|
+
validation: (0, import_ui_builder_utils30.enhanceNumericValidation)(
|
|
4314
|
+
getDefaultValidation(),
|
|
4315
|
+
parameter.type,
|
|
4316
|
+
EVM_NUMERIC_BOUNDS
|
|
4317
|
+
),
|
|
4269
4318
|
width: "full"
|
|
4270
4319
|
};
|
|
4271
4320
|
if (fieldType === "array") {
|
|
@@ -4277,7 +4326,11 @@ function generateEvmDefaultField(parameter) {
|
|
|
4277
4326
|
elementType: elementFieldType,
|
|
4278
4327
|
elementFieldConfig: {
|
|
4279
4328
|
type: elementFieldType,
|
|
4280
|
-
validation:
|
|
4329
|
+
validation: (0, import_ui_builder_utils30.enhanceNumericValidation)(
|
|
4330
|
+
getDefaultValidation(),
|
|
4331
|
+
elementType,
|
|
4332
|
+
EVM_NUMERIC_BOUNDS
|
|
4333
|
+
),
|
|
4281
4334
|
placeholder: `Enter ${elementType}`
|
|
4282
4335
|
}
|
|
4283
4336
|
};
|
|
@@ -5833,6 +5886,12 @@ var EvmAdapter = class {
|
|
|
5833
5886
|
}
|
|
5834
5887
|
return null;
|
|
5835
5888
|
}
|
|
5889
|
+
/**
|
|
5890
|
+
* @inheritdoc
|
|
5891
|
+
*/
|
|
5892
|
+
async getCurrentBlock() {
|
|
5893
|
+
return getEvmCurrentBlock(this.networkConfig);
|
|
5894
|
+
}
|
|
5836
5895
|
/**
|
|
5837
5896
|
* @inheritdoc
|
|
5838
5897
|
*/
|