fix: properly build schema before using it

This commit is contained in:
Rafael Taranto 2025-02-06 11:12:42 +00:00
parent 7d11bfacb0
commit fca5c73587
11 changed files with 2045 additions and 2224 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,20 @@
with import (fetchTarball {
name = "nixpkgs-194846768975b7ad2c4988bdb82572c00222c0d7";
url = https://github.com/NixOS/nixpkgs/archive/194846768975b7ad2c4988bdb82572c00222c0d7.tar.gz;
sha256 = "0snj72i9dm99jlnnmk8id8ffjnfg1k81lr7aw8d01kz3hdiraqil";
}) {};
stdenv.mkDerivation {
name = "node";
buildInputs = [
nodejs_22
openssl
python3
entr
yasm
];
shellHook = ''
export PATH="$PWD/node_modules/.bin/:$PATH"
'';
}

View file

@ -176,6 +176,7 @@ const Wallet = ({ name: SCREEN_KEY }) => {
coin={R.find(R.propEq('code', wizard))(cryptoCurrencies)}
onClose={() => setWizard(false)}
save={save}
schemas={schemas}
error={error?.message}
cryptoCurrencies={cryptoCurrencies}
fiatCurrency={fiatCurrency}

View file

@ -3,7 +3,7 @@ import React, { useState } from 'react'
import Modal from 'src/components/Modal'
import * as Yup from 'yup'
import schema from 'src/pages/Services/schemas'
import _schema from 'src/pages/Services/schemas'
import { toNamespace } from 'src/utils/config'
import WizardSplash from './WizardSplash'
@ -21,6 +21,7 @@ const removeDeprecated = R.filter(({ deprecated }) => !deprecated)
const getItems = (accountsConfig, accounts, type, crypto) => {
const fConfig = removeDeprecated(filterConfig(crypto, type)(accountsConfig))
const schema = _schema()
const find = code => accounts && accounts[code]
@ -38,6 +39,7 @@ const getItems = (accountsConfig, accounts, type, crypto) => {
const Wizard = ({
coin,
onClose,
schemas,
accountsConfig,
accounts,
fiatCurrency,
@ -128,6 +130,7 @@ const Wizard = ({
)}
{step !== 0 && (
<WizardStep
schemas={schemas}
coin={coin.display}
fiatCurrency={fiatCurrency}
error={error}

View file

@ -11,7 +11,6 @@ import FormRenderer from 'src/pages/Services/FormRenderer'
import { Button } from 'src/components/buttons'
import { RadioGroup, Autocomplete } from 'src/components/inputs'
import { NumberInput } from 'src/components/inputs/formik'
import schema from 'src/pages/Services/schemas'
import { startCase } from 'src/utils/string'
import styles from './WizardStep.styles'
@ -55,6 +54,7 @@ const reducer = (state, action) => {
const WizardStep = ({
type,
schema: stepSchema,
schemas,
coin,
name,
error,
@ -176,8 +176,8 @@ const WizardStep = ({
{form && (
<FormRenderer
save={it => innerContinue({ [type]: form.code }, { [form.code]: it })}
elements={schema[form.code].elements}
validationSchema={schema[form.code].validationSchema}
elements={schemas[form.code].elements}
validationSchema={schemas[form.code].validationSchema}
value={getValue(form.code)}
buttonLabel={label}
/>

View file

@ -10,7 +10,7 @@ import WarningIcon from 'src/styling/icons/warning-icon/comet.svg?react'
import { ActionButton } from 'src/components/buttons'
import { RadioGroup } from 'src/components/inputs'
import schema from 'src/pages/Services/schemas'
import mailgunSchema from 'src/pages/Services/schemas/mailgun'
import styles from 'src/pages/Wizard/Radio.styles'
import { fromNamespace, toNamespace, namespaces } from 'src/utils/config'
@ -125,8 +125,8 @@ const Mailgun = () => {
<FormRenderer
value={accounts.mailgun}
save={saveAccount}
elements={schema.mailgun.elements}
validationSchema={schema.mailgun.validationSchema}
elements={mailgunSchema.elements}
validationSchema={mailgunSchema.validationSchema}
buttonLabel={'Save'}
/>
</>

View file

@ -7,7 +7,7 @@ import FormRenderer from 'src/pages/Services/FormRenderer'
import { SupportLinkButton, Button } from 'src/components/buttons'
import { RadioGroup } from 'src/components/inputs'
import schema from 'src/pages/Services/schemas'
import blockcypherSchema from 'src/pages/Services/schemas/blockcypher'
import styles from './Shared.styles'
@ -95,8 +95,8 @@ const Blockcypher = ({ addData }) => {
<FormRenderer
value={accounts.blockcypher}
save={save}
elements={schema.blockcypher.elements}
validationSchema={schema.blockcypher.getValidationSchema}
elements={blockcypherSchema.elements}
validationSchema={blockcypherSchema.getValidationSchema}
buttonLabel={'Continue'}
buttonClass={classes.formButton}
/>

View file

@ -10,7 +10,7 @@ import WarningIcon from 'src/styling/icons/warning-icon/comet.svg?react'
import { Button, SupportLinkButton } from 'src/components/buttons'
import { RadioGroup } from 'src/components/inputs'
import schema from 'src/pages/Services/schemas'
import _schema from 'src/pages/Services/schemas'
import styles from './Shared.styles'
import { getItems } from './getItems'
@ -52,6 +52,7 @@ const ChooseExchange = ({ data: currentData, addData }) => {
const [selected, setSelected] = useState(null)
const [error, setError] = useState(false)
const schema = _schema()
const accounts = data?.accounts ?? []
const accountsConfig = data?.accountsConfig ?? []

View file

@ -9,7 +9,7 @@ import WarningIcon from 'src/styling/icons/warning-icon/comet.svg?react'
import { Button, SupportLinkButton } from 'src/components/buttons'
import { RadioGroup } from 'src/components/inputs'
import schema from 'src/pages/Services/schemas'
import _schema from 'src/pages/Services/schemas'
import bitgo from 'src/pages/Services/schemas/singlebitgo'
import styles from './Shared.styles'
@ -54,6 +54,8 @@ const isLocalHosted = it =>
const ChooseWallet = ({ data: currentData, addData }) => {
const classes = useStyles()
// no need to fetch exchange config here
const schema = _schema()
const { data } = useQuery(GET_CONFIG)
const [saveAccounts] = useMutation(SAVE_ACCOUNTS, {
onCompleted: () => submit()

View file

@ -1,11 +1,13 @@
import * as R from 'ramda'
import schema from 'src/pages/Services/schemas'
import _schema from 'src/pages/Services/schemas'
const contains = crypto => R.compose(R.contains(crypto), R.prop('cryptos'))
const sameClass = type => R.propEq('class', type)
const filterConfig = (crypto, type) =>
R.filter(it => sameClass(type)(it) && contains(crypto)(it))
export const getItems = (accountsConfig, accounts, type, crypto) => {
const schema = _schema()
const fConfig = filterConfig(crypto, type)(accountsConfig)
const find = code => accounts && accounts[code]

125
package-lock.json generated
View file

@ -990,6 +990,38 @@
"secp256k1": "^4.0.2",
"secrets.js-grempe": "^1.1.0",
"superagent": "3.8.3"
},
"dependencies": {
"bech32": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
},
"bitcoinjs-message": {
"version": "npm:@bitgo-forks/bitcoinjs-message@1.0.0-master.2",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bitcoinjs-message/-/bitcoinjs-message-1.0.0-master.2.tgz",
"integrity": "sha512-XSDGM3rA75vcDxeKqHPexika/TgWUFWdfKTv1lV8TZTb5XFHHD6ARckLdMOBiCf29eZSzbJQvF/OIWqNqMl/2A==",
"requires": {
"bech32": "^1.1.3",
"bs58check": "^2.1.2",
"buffer-equals": "^1.0.3",
"create-hash": "^1.1.2",
"secp256k1": "5.0.0",
"varuint-bitcoin": "^1.0.1"
},
"dependencies": {
"secp256k1": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-5.0.0.tgz",
"integrity": "sha512-TKWX8xvoGHrxVdqbYeZM9w+izTF4b9z3NhSaDkdn81btvuh+ivbIMGT/zQvDtTFWhRlThpoz6LEYTr7n8A5GcA==",
"requires": {
"elliptic": "^6.5.4",
"node-addon-api": "^5.0.0",
"node-gyp-build": "^4.2.0"
}
}
}
}
}
},
"@bitgo/sdk-coin-bch": {
@ -1105,11 +1137,6 @@
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
},
"buffer-equals": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/buffer-equals/-/buffer-equals-1.0.4.tgz",
"integrity": "sha512-99MsCq0j5+RhubVEtKQgKaD6EM+UP3xJgIvQqwJ3SOLDUekzxMX1ylXBng+Wa2sh7mGT0W6RUly8ojjr1Tt6nA=="
}
}
},
@ -1203,40 +1230,6 @@
"fastpriorityqueue": "^0.7.1",
"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.1.2"
},
"dependencies": {
"bip174": {
"version": "npm:@bitgo-forks/bip174@3.1.0-master.4",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bip174/-/bip174-3.1.0-master.4.tgz",
"integrity": "sha512-WDRNzPSdJGDqQNqfN+L5KHNHFDmNOPYnUnT7NkEkfHWn5m1jSOfcf8Swaslt5P0xcSDiERdN2gZxFc6XtOqRYg=="
},
"bitcoinjs-lib": {
"version": "npm:@bitgo-forks/bitcoinjs-lib@7.1.0-master.7",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bitcoinjs-lib/-/bitcoinjs-lib-7.1.0-master.7.tgz",
"integrity": "sha512-FZle7954KnbbVXFCc5uYGtjq+0PFOnFxVchNwt3Kcv2nVusezTp29aeQwDi2Y+lM1dCoup2gJGXMkkREenY7KQ==",
"requires": {
"bech32": "^2.0.0",
"bip174": "npm:@bitgo-forks/bip174@3.1.0-master.4",
"bs58check": "^2.1.2",
"create-hash": "^1.1.0",
"fastpriorityqueue": "^0.7.1",
"json5": "^2.2.3",
"ripemd160": "^2.0.2",
"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.1.2",
"wif": "^2.0.1"
}
},
"ecpair": {
"version": "npm:@bitgo/ecpair@2.1.0-rc.0",
"resolved": "https://registry.npmjs.org/@bitgo/ecpair/-/ecpair-2.1.0-rc.0.tgz",
"integrity": "sha512-qPZetcEA1Lzzm9NsqsGF9NGorAGaXrv20eZjopLUjsdwftWcsYTE7lwzE/Xjdf4fcq6G4+vjrCudWAMGNfJqOQ==",
"requires": {
"randombytes": "^2.1.0",
"typeforce": "^1.18.0",
"wif": "^2.0.6"
}
}
}
},
"@bitgo/utxo-ord": {
@ -4318,6 +4311,11 @@
"safe-buffer": "^5.2.1"
}
},
"bip174": {
"version": "npm:@bitgo-forks/bip174@3.1.0-master.4",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bip174/-/bip174-3.1.0-master.4.tgz",
"integrity": "sha512-WDRNzPSdJGDqQNqfN+L5KHNHFDmNOPYnUnT7NkEkfHWn5m1jSOfcf8Swaslt5P0xcSDiERdN2gZxFc6XtOqRYg=="
},
"bip32": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/bip32/-/bip32-3.1.0.tgz",
@ -4356,34 +4354,21 @@
"resolved": "https://registry.npmjs.org/bitcoin-ops/-/bitcoin-ops-1.4.1.tgz",
"integrity": "sha512-pef6gxZFztEhaE9RY9HmWVmiIHqCb2OyS4HPKkpc6CIiiOa3Qmuoylxc5P2EkU3w+5eTSifI9SEZC88idAIGow=="
},
"bitcoinjs-message": {
"version": "npm:@bitgo-forks/bitcoinjs-message@1.0.0-master.2",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bitcoinjs-message/-/bitcoinjs-message-1.0.0-master.2.tgz",
"integrity": "sha512-XSDGM3rA75vcDxeKqHPexika/TgWUFWdfKTv1lV8TZTb5XFHHD6ARckLdMOBiCf29eZSzbJQvF/OIWqNqMl/2A==",
"bitcoinjs-lib": {
"version": "npm:@bitgo-forks/bitcoinjs-lib@7.1.0-master.7",
"resolved": "https://registry.npmjs.org/@bitgo-forks/bitcoinjs-lib/-/bitcoinjs-lib-7.1.0-master.7.tgz",
"integrity": "sha512-FZle7954KnbbVXFCc5uYGtjq+0PFOnFxVchNwt3Kcv2nVusezTp29aeQwDi2Y+lM1dCoup2gJGXMkkREenY7KQ==",
"requires": {
"bech32": "^1.1.3",
"bech32": "^2.0.0",
"bip174": "npm:@bitgo-forks/bip174@3.1.0-master.4",
"bs58check": "^2.1.2",
"buffer-equals": "^1.0.3",
"create-hash": "^1.1.2",
"secp256k1": "5.0.0",
"varuint-bitcoin": "^1.0.1"
},
"dependencies": {
"bech32": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/bech32/-/bech32-1.1.4.tgz",
"integrity": "sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ=="
},
"secp256k1": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/secp256k1/-/secp256k1-5.0.0.tgz",
"integrity": "sha512-TKWX8xvoGHrxVdqbYeZM9w+izTF4b9z3NhSaDkdn81btvuh+ivbIMGT/zQvDtTFWhRlThpoz6LEYTr7n8A5GcA==",
"requires": {
"elliptic": "^6.5.4",
"node-addon-api": "^5.0.0",
"node-gyp-build": "^4.2.0"
}
}
"create-hash": "^1.1.0",
"fastpriorityqueue": "^0.7.1",
"json5": "^2.2.3",
"ripemd160": "^2.0.2",
"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.1.2",
"wif": "^2.0.1"
}
},
"bitcore-lib": {
@ -6195,6 +6180,16 @@
"safe-buffer": "^5.0.1"
}
},
"ecpair": {
"version": "npm:@bitgo/ecpair@2.1.0-rc.0",
"resolved": "https://registry.npmjs.org/@bitgo/ecpair/-/ecpair-2.1.0-rc.0.tgz",
"integrity": "sha512-qPZetcEA1Lzzm9NsqsGF9NGorAGaXrv20eZjopLUjsdwftWcsYTE7lwzE/Xjdf4fcq6G4+vjrCudWAMGNfJqOQ==",
"requires": {
"randombytes": "^2.1.0",
"typeforce": "^1.18.0",
"wif": "^2.0.6"
}
},
"ecurve": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/ecurve/-/ecurve-1.0.6.tgz",