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

feat: add an amount field to specify pCKB sent along with a tx #908

Merged
merged 1 commit into from
Feb 21, 2023
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
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": "与交易一起发送"
}