Skip to content

Commit

Permalink
Merge pull request #908 from Magickbase/add-amount-field-on-writing-c…
Browse files Browse the repository at this point in the history
…ontract

feat: add an amount field to specify pCKB sent along with a tx
  • Loading branch information
FrederLu authored Feb 21, 2023
2 parents 2b39afa + fb2823d commit 895d0de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 10 additions & 2 deletions components/ContractInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { PolyjuiceContract as PolyjuiceContractProps } from 'components/Acc
import { useState, useEffect } from 'react'
import { useTranslation } from 'next-i18next'
import NextLink from 'next/link'
import { utils } from 'ethers'
import OpenInNewIcon from 'assets/icons/open-in-new.svg'
import ExpandIcon from 'assets/icons/expand.svg'
import { currentChain as targetChain } from 'utils'
Expand Down Expand Up @@ -149,7 +150,8 @@ const ContractInfo: React.FC<{ address: string; contract: PolyjuiceContractProps
form.setAttribute(LOADING_ATTRIBUTE, 'true')

try {
const result = await method(...params)
const pCKB = form.querySelector<HTMLInputElement>('input[name=pCKB]')?.value ?? '0'
const result = await method(...params, { value: utils.parseEther(pCKB) })
if (tabIdx === 2) {
const elm = resInputList[0]
if (elm) {
Expand Down Expand Up @@ -340,7 +342,7 @@ const ContractInfo: React.FC<{ address: string; contract: PolyjuiceContractProps
) : null}
<div className={styles.methodGroupTitle}>Non-payable and Payable</div>
{Object.keys(writeMethods).map(signature => {
const { inputs = [], outputs = [] } = contract.interface.functions[signature] ?? {}
const { inputs = [], outputs = [], payable } = contract.interface.functions[signature] ?? {}
return (
<details key={signature}>
<summary>
Expand All @@ -362,6 +364,12 @@ const ContractInfo: React.FC<{ address: string; contract: PolyjuiceContractProps
</fieldset>
)
})}
{payable ? (
<fieldset key="pCKB">
<label>pCKB</label>
<input name="pCKB" title="pCKB" placeholder={t('pckb_send_along_with_tx')} />
</fieldset>
) : null}
<div className={styles.response}>Response</div>
<fieldset>
<label>Txn Hash</label>
Expand Down
3 changes: 2 additions & 1 deletion public/locales/en-US/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@
"erc721Assets": "ERC 721 Assets",
"erc1155Assets": "ERC 1155 Assets",
"erc20Assets": "ERC 20 Assets",
"invalidAddress": "*Invalid address format"
"invalidAddress": "*Invalid address format",
"pckb_send_along_with_tx": "Send along with the transaction"
}
3 changes: 2 additions & 1 deletion public/locales/zh-CN/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,6 @@
"erc721Assets": "ERC 721 资产",
"erc1155Assets": "ERC 1155 资产",
"erc20Assets": "ERC 20 资产",
"invalidAddress": "*无效的地址格式"
"invalidAddress": "*无效的地址格式",
"pckb_send_along_with_tx": "与交易一起发送"
}

0 comments on commit 895d0de

Please sign in to comment.