Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse array values when interacting with contracts #228

Merged
merged 5 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading