|
|
@ -122,31 +122,51 @@ function callMethod (isWalletEnabled, $functionInputs, explorerChainId, $form, f |
|
|
|
const warningMsg = 'You haven\'t approved the reading of account list from your MetaMask or MetaMask/Nifty wallet is locked or is not installed.' |
|
|
|
const warningMsg = 'You haven\'t approved the reading of account list from your MetaMask or MetaMask/Nifty wallet is locked or is not installed.' |
|
|
|
return openWarningModal('Unauthorized', warningMsg) |
|
|
|
return openWarningModal('Unauthorized', warningMsg) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const contractAbi = getContractABI($form) |
|
|
|
|
|
|
|
const functionAbi = contractAbi.find(abi => |
|
|
|
|
|
|
|
abi.name === functionName |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
const inputs = functionAbi && functionAbi.inputs |
|
|
|
|
|
|
|
|
|
|
|
const $functionInputsExceptTxValue = $functionInputs.filter(':not([tx-value])') |
|
|
|
const $functionInputsExceptTxValue = $functionInputs.filter(':not([tx-value])') |
|
|
|
const args = $.map($functionInputsExceptTxValue, element => $(element).val()) |
|
|
|
const args = $.map($functionInputsExceptTxValue, (element, ind) => { |
|
|
|
|
|
|
|
const val = $(element).val() |
|
|
|
|
|
|
|
const inputType = inputs[ind] && inputs[ind].type |
|
|
|
|
|
|
|
let preparedVal |
|
|
|
|
|
|
|
if (isNonSpaceInputType(inputType)) { preparedVal = val.replace(/\s/g, '') } else { preparedVal = val } |
|
|
|
|
|
|
|
if (isArrayInputType(inputType)) { |
|
|
|
|
|
|
|
return preparedVal.split(',') |
|
|
|
|
|
|
|
} else { return preparedVal } |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const txValue = getTxValue($functionInputs) |
|
|
|
const txValue = getTxValue($functionInputs) |
|
|
|
const contractAddress = $form.data('contract-address') |
|
|
|
const contractAddress = $form.data('contract-address') |
|
|
|
const contractAbi = getContractABI($form) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { chainId: walletChainIdHex } = window.ethereum |
|
|
|
const { chainId: walletChainIdHex } = window.ethereum |
|
|
|
compareChainIDs(explorerChainId, walletChainIdHex) |
|
|
|
compareChainIDs(explorerChainId, walletChainIdHex) |
|
|
|
.then(currentAccount => { |
|
|
|
.then(currentAccount => { |
|
|
|
if (functionName) { |
|
|
|
if (functionName) { |
|
|
|
const TargetContract = new window.web3.eth.Contract(contractAbi, contractAddress) |
|
|
|
const TargetContract = new window.web3.eth.Contract(contractAbi, contractAddress) |
|
|
|
const functionAbi = contractAbi.find(abi => |
|
|
|
const inputsCount = inputs && inputs.length |
|
|
|
abi.name === functionName |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
const inputsCount = functionAbi && functionAbi.inputs.length |
|
|
|
|
|
|
|
let methodToCall |
|
|
|
let methodToCall |
|
|
|
const sendParams = { from: currentAccount, value: txValue || 0 } |
|
|
|
const sendParams = { from: currentAccount, value: txValue || 0 } |
|
|
|
if (inputsCount > 1) { |
|
|
|
if (inputsCount > 1) { |
|
|
|
methodToCall = TargetContract.methods[functionName](...args).send(sendParams) |
|
|
|
methodToCall = TargetContract.methods[functionName](...args).send(sendParams) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
const inputType = inputs[0] && inputs[0].type |
|
|
|
if (Array.isArray(args) && args[0] === '') { |
|
|
|
if (Array.isArray(args) && args[0] === '') { |
|
|
|
|
|
|
|
if (isArrayInputType(inputType)) { |
|
|
|
methodToCall = TargetContract.methods[functionName]([]).send(sendParams) |
|
|
|
methodToCall = TargetContract.methods[functionName]([]).send(sendParams) |
|
|
|
} else { methodToCall = TargetContract.methods[functionName](args).send(sendParams) } |
|
|
|
} else { |
|
|
|
|
|
|
|
methodToCall = TargetContract.methods[functionName]().send(sendParams) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
if (isArrayInputType(inputType)) { |
|
|
|
|
|
|
|
methodToCall = TargetContract.methods[functionName](args).send(sendParams) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
methodToCall = TargetContract.methods[functionName](args[0]).send(sendParams) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
methodToCall |
|
|
|
methodToCall |
|
|
|
.on('error', function (error) { |
|
|
|
.on('error', function (error) { |
|
|
@ -178,6 +198,14 @@ function callMethod (isWalletEnabled, $functionInputs, explorerChainId, $form, f |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isArrayInputType (inputType) { |
|
|
|
|
|
|
|
return inputType && inputType.includes('[]') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function isNonSpaceInputType (inputType) { |
|
|
|
|
|
|
|
return inputType.includes('address') || inputType.includes('int') || inputType.includes('bool') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getTxValue ($functionInputs) { |
|
|
|
function getTxValue ($functionInputs) { |
|
|
|
const WEI_MULTIPLIER = 10 ** 18 |
|
|
|
const WEI_MULTIPLIER = 10 ** 18 |
|
|
|
const $txValue = $functionInputs.filter('[tx-value]:first') |
|
|
|
const $txValue = $functionInputs.filter('[tx-value]:first') |
|
|
|