@snapshot-labs/snapshot.js 0.4.96 → 0.4.97

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.d.ts CHANGED
@@ -249,7 +249,7 @@ declare const _default: {
249
249
  };
250
250
  delegationContract: {
251
251
  type: string;
252
- pattern: string;
252
+ format: string;
253
253
  title: string;
254
254
  description: string;
255
255
  examples: string[];
@@ -245,7 +245,7 @@ declare const _default: {
245
245
  };
246
246
  delegationContract: {
247
247
  type: string;
248
- pattern: string;
248
+ format: string;
249
249
  title: string;
250
250
  description: string;
251
251
  examples: string[];
@@ -4,6 +4,7 @@ var fetch = require('cross-fetch');
4
4
  var address = require('@ethersproject/address');
5
5
  var abi = require('@ethersproject/abi');
6
6
  var contracts = require('@ethersproject/contracts');
7
+ var units = require('@ethersproject/units');
7
8
  var ethEnsNamehash = require('@ensdomains/eth-ens-namehash');
8
9
  var jsonToGraphqlQuery = require('json-to-graphql-query');
9
10
  var Ajv = require('ajv');
@@ -767,7 +768,7 @@ var definitions = {
767
768
  },
768
769
  delegationContract: {
769
770
  type: "string",
770
- pattern: "^0x[a-fA-F0-9]{40}$",
771
+ format: "address",
771
772
  title: "Contract address",
772
773
  description: "The address of your delegation contract",
773
774
  examples: [
@@ -4023,6 +4024,32 @@ var ENS_RESOLVER_ABI = [
4023
4024
  var ajv = new Ajv__default['default']({ allErrors: true, allowUnionTypes: true, $data: true });
4024
4025
  // @ts-ignore
4025
4026
  addFormats__default['default'](ajv);
4027
+ ajv.addFormat('address', {
4028
+ validate: function (value) {
4029
+ try {
4030
+ return address.isAddress(value);
4031
+ }
4032
+ catch (err) {
4033
+ return false;
4034
+ }
4035
+ }
4036
+ });
4037
+ ajv.addFormat('long', {
4038
+ validate: function () { return true; }
4039
+ });
4040
+ ajv.addFormat('ethValue', {
4041
+ validate: function (value) {
4042
+ if (!value.match(/^([0-9]|[1-9][0-9]+)(\.[0-9]+)?$/))
4043
+ return false;
4044
+ try {
4045
+ units.parseUnits(value, 18);
4046
+ return true;
4047
+ }
4048
+ catch (_a) {
4049
+ return false;
4050
+ }
4051
+ }
4052
+ });
4026
4053
  // Custom URL format to allow empty string values
4027
4054
  // https://github.com/snapshot-labs/snapshot.js/pull/541/files
4028
4055
  ajv.addFormat('customUrl', {
@@ -2,6 +2,7 @@ import fetch from 'cross-fetch';
2
2
  import { getAddress, isAddress } from '@ethersproject/address';
3
3
  import { Interface } from '@ethersproject/abi';
4
4
  import { Contract } from '@ethersproject/contracts';
5
+ import { parseUnits } from '@ethersproject/units';
5
6
  import { hash, normalize } from '@ensdomains/eth-ens-namehash';
6
7
  import { jsonToGraphQLQuery } from 'json-to-graphql-query';
7
8
  import Ajv from 'ajv';
@@ -758,7 +759,7 @@ var definitions = {
758
759
  },
759
760
  delegationContract: {
760
761
  type: "string",
761
- pattern: "^0x[a-fA-F0-9]{40}$",
762
+ format: "address",
762
763
  title: "Contract address",
763
764
  description: "The address of your delegation contract",
764
765
  examples: [
@@ -4014,6 +4015,32 @@ var ENS_RESOLVER_ABI = [
4014
4015
  var ajv = new Ajv({ allErrors: true, allowUnionTypes: true, $data: true });
4015
4016
  // @ts-ignore
4016
4017
  addFormats(ajv);
4018
+ ajv.addFormat('address', {
4019
+ validate: function (value) {
4020
+ try {
4021
+ return isAddress(value);
4022
+ }
4023
+ catch (err) {
4024
+ return false;
4025
+ }
4026
+ }
4027
+ });
4028
+ ajv.addFormat('long', {
4029
+ validate: function () { return true; }
4030
+ });
4031
+ ajv.addFormat('ethValue', {
4032
+ validate: function (value) {
4033
+ if (!value.match(/^([0-9]|[1-9][0-9]+)(\.[0-9]+)?$/))
4034
+ return false;
4035
+ try {
4036
+ parseUnits(value, 18);
4037
+ return true;
4038
+ }
4039
+ catch (_a) {
4040
+ return false;
4041
+ }
4042
+ }
4043
+ });
4017
4044
  // Custom URL format to allow empty string values
4018
4045
  // https://github.com/snapshot-labs/snapshot.js/pull/541/files
4019
4046
  ajv.addFormat('customUrl', {