Skip to content

Commit

Permalink
Merge pull request #228 from rsksmart/staging
Browse files Browse the repository at this point in the history
Parse array values when interacting with contracts
  • Loading branch information
nicov-iov authored Jul 17, 2024
2 parents f7fd5b2 + e5009bc commit 0f7169a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
{
"name": "rsk-explorer",
"version": "2.0.0",
"version": "2.0.1",
"private": true,
"description": "Rsk explorer client",
"author": "emi <[email protected]>",
"scripts": {
"dev:mainnet": "env-cmd -f .env.mainnet npx vue-cli-service serve",
"dev:testnet": "env-cmd -f .env.testnet npx vue-cli-service serve",
"dev:staging": "env-cmd -f .env.staging npx vue-cli-service serve",
"dev:local": "env-cmd -f .env.local npx vue-cli-service serve",
"dev-with-tracking:mainnet": "env-cmd -f .env.mainnet npx vue-cli-service serve src/main.with.tracking.js",
"dev-with-tracking:testnet": "env-cmd -f .env.testnet npx vue-cli-service serve src/main.with.tracking.js",
"dev-with-tracking:staging": "env-cmd -f .env.staging npx vue-cli-service serve src/main.with.tracking.js",
"dev-with-tracking:local": "env-cmd -f .env.local npx vue-cli-service serve src/main.with.tracking.js",
"build:mainnet": "env-cmd -f .env.mainnet npx vue-cli-service build --modern",
"build:testnet": "env-cmd -f .env.testnet npx vue-cli-service build --modern",
"build:staging": "env-cmd -f .env.staging npx vue-cli-service build --modern",
"build:local": "env-cmd -f .env.local npx vue-cli-service build --modern",
"build-with-tracking:mainnet": "env-cmd -f .env.mainnet npx vue-cli-service build src/main.with.tracking.js --modern",
"build-with-tracking:testnet": "env-cmd -f .env.testnet npx vue-cli-service build src/main.with.tracking.js --modern",
"build-with-tracking:staging": "env-cmd -f .env.staging npx vue-cli-service build src/main.with.tracking.js --modern",
"build-with-tracking:local": "env-cmd -f .env.local npx vue-cli-service build src/main.with.tracking.js --modern",
"test:unit": "npx vue-cli-service test:unit",
"test:e2e": "npx vue-cli-service test:e2e",
"lint": "npx vue-cli-service lint",
Expand Down
11 changes: 11 additions & 0 deletions src/components/ContractInteraction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ export default {
this.validateInputs(inputs, method)
// TODO: abstract inputs formatter
method.inputs.forEach((input, index) => {
const { type } = input
Expand All @@ -352,6 +353,8 @@ export default {
throw new Error('Invalid boolean input (possible values: true, false, 1, 0)')
} else if (type.startsWith('uint') || type.startsWith('int')) {
args[index] = this.formatBigNumber(args[index])
} else if (type.includes('[]')) {
args[index] = this.parseArrayFromString(args[index])
}
})
Expand Down Expand Up @@ -380,6 +383,7 @@ export default {
const contract = this.getReadOnlyContractInstance()
const args = inputs
// TODO: abstract inputs formatter
method.inputs.forEach((input, index) => {
const { type } = input
Expand All @@ -388,6 +392,8 @@ export default {
args[index] = this.normalizeAddress(args[index])
} else if (type === 'bool') {
if (!this.isValidBoolean(args[index])) throw new Error('Invalid boolean input (possible values: true, false, 1, 0)')
} else if (type.includes('[]')) {
args[index] = this.parseArrayFromString(args[index])
}
})
Expand All @@ -413,6 +419,11 @@ export default {
this.$set(method.interactionData, 'requested', false)
},
parseArrayFromString (str) {
if (!str.startsWith('[') || !str.endsWith(']')) throw new Error('Value must be a valid array')
return JSON.parse(str)
},
validateInputs (inputs, method) {
const nonEmptyInputs = inputs.filter(input => input !== '' && input !== undefined && input !== null)
Expand Down
4 changes: 2 additions & 2 deletions src/jsonRpcProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (!['mainnet', 'testnet'].includes(envNetwork)) throw new Error(`Invalid env n

export const rskNetworks = {
mainnet: {
chainName: 'Rootstock Mainnet - RPC API',
chainName: 'Rootstock Mainnet',
chainId: '0x1e', // 30
nativeCurrency: {
name: 'Smart Bitcoin',
Expand All @@ -22,7 +22,7 @@ export const rskNetworks = {
]
},
testnet: {
chainName: 'Rootstock Testnet - RPC API',
chainName: 'Rootstock Testnet',
chainId: '0x1f', // 31
nativeCurrency: {
name: 'Test Smart Bitcoin',
Expand Down

0 comments on commit 0f7169a

Please sign in to comment.