Skip to content

Commit

Permalink
chore: WIP, added value field if payable
Browse files Browse the repository at this point in the history
  • Loading branch information
athoifss committed Nov 29, 2024
1 parent 6413149 commit d880534
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/components/CommonPage/DetailPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ class DetailPage extends Component {
const { loading, error, pending } = this.props
const isNotFoundPage = !loading && error !== '' && !isHxAddress(error) && !pending

console.log("Detail Page", this.state)

const Content = () => {
if (pending) {
return <PendingPage error={error} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,24 @@ function ContractComponent({
alert('Please connect to wallet first')
} else {
const paramsData = makeParams(params, method, inputs)
let value = null;
if (paramsData.hasOwnProperty("value")) {
value = paramsData.value;
const valueInput = inputs.find(f => f.name === 'value' && f.type === "icx");
if (valueInput) {
value = parseFloat(value);
}
delete paramsData.value;
}


const rawMethodCall = await customMethod(
walletAddress,
address,
method,
paramsData,
nid
nid,
value
)
icxSendTransaction({
params: { ...rawMethodCall },
Expand Down
11 changes: 11 additions & 0 deletions src/components/ContractsPage/contractUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,22 @@ export function createContractMethodsState(contractReadWriteInfo) {
result.writeMethodsNameArray.push(funcName)
const inputs = { ...func }


if (inputs.payable === "0x1") {
if (!inputs.inputs.find(f => f.name === 'value')) {
inputs.inputs.push({ name: 'value', type: 'icx' })
}
}



const outputs = writeFuncOutputs[index]
result[funcName] = {
inputs,
outputs,
}


})

return result
Expand Down
7 changes: 5 additions & 2 deletions src/redux/api/jsProvider/icx.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { requestJsonRpc } from '../../../utils/connect'
export async function icxSendTransaction(payload) {
console.log('icxSendTransaction payload:', payload)


// payload will always have an 'index' field
const { index } = payload
const result = {
Expand All @@ -18,6 +19,8 @@ export async function icxSendTransaction(payload) {
if (rawTx == null) {
throw new Error('Invalid payload for icxSendTransaction')
}


result.data = await requestJsonRpc(rawTx.params)
console.log('result success')
} catch (e) {
Expand All @@ -28,8 +31,8 @@ export async function icxSendTransaction(payload) {
typeof e === 'string'
? e
: e.message != null && typeof e.message === 'string'
? e.message
: JSON.stringify(e)
? e.message
: JSON.stringify(e)
}
return result
}
4 changes: 2 additions & 2 deletions src/utils/rawTxMaker/api/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { makeTxCallRPCObj } from './helpers'
/*
*
*/
async function customMethod(from, to, methodName, methodParams, nid) {
const RPCObj = await makeTxCallRPCObj(from, to, methodName, methodParams, nid)
async function customMethod(from, to, methodName, methodParams, nid, value = null) {
const RPCObj = await makeTxCallRPCObj(from, to, methodName, methodParams, nid, null, value)
return RPCObj
}

Expand Down
7 changes: 6 additions & 1 deletion src/utils/rawTxMaker/api/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ async function makeTxCallRPCObj(
method,
paramsObj = null,
nid,
stepLimit = 2000000,
stepLimit,
value = null
) {

if (!stepLimit) {
stepLimit = 2000000
}

const params = {
from: from,
to: to,
Expand Down

0 comments on commit d880534

Please sign in to comment.