Skip to content

Commit

Permalink
fix: fix modification of token info (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY authored Feb 6, 2024
1 parent b2c08c8 commit e5d8ebb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/components/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ export default memo(() => {
<span>{`Copyright © ${getCurrentYear()} Nervos Foundation. `}</span>
<span>All Rights Reserved.</span>
</div>
<SubmitTokenInfo isOpen={isTokenFormDisplayed} onClose={() => setIsTokenFormDisplayed(false)} />
{isTokenFormDisplayed ? <SubmitTokenInfo onClose={() => setIsTokenFormDisplayed(false)} /> : null}
</FooterPanel>
)
})
37 changes: 21 additions & 16 deletions src/components/SubmitTokenInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ const useCountdown = () => {

export const SubmitTokenInfo = ({
onClose,
isOpen,
initialInfo,
onSuccess,
}: {
isOpen: boolean
onClose: () => void
initialInfo?: TokenInfo
onSuccess?: Function
Expand All @@ -120,7 +118,7 @@ export const SubmitTokenInfo = ({

const scriptDataList = isMainnet() ? MainnetContractHashTags : TestnetContractHashTags
const tokenTypeOptions = scriptDataList
.filter(scriptData => scriptData.tag.includes('sudt'))
.filter(scriptData => scriptData.tag === 'sudt')
.sort((a, b) => a.tag.localeCompare(b.tag))
.map(scriptData => ({ label: scripts.get(scriptData.tag)?.name ?? scriptData.tag, value: scriptData.tag }))

Expand Down Expand Up @@ -177,10 +175,8 @@ export const SubmitTokenInfo = ({

useEffect(() => {
// scroll to top when open modal
if (isOpen) {
window.scrollTo(0, 0)
}
}, [isOpen])
window.scrollTo(0, 0)
}, [])

const handleImgChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const file = e.target.files?.[0]
Expand Down Expand Up @@ -238,15 +234,24 @@ export const SubmitTokenInfo = ({
}

setSubmitting(true)
const token = scriptDataList.find(scriptData => scriptData.tag === tokenInfo.tokenType)
if (!token) {
throw new Error(`tokenType ${tokenInfo.tokenType} is not found`)

let typeHash = ''
if (isModification) {
typeHash = tokenInfo.typeHash
} else {
const token = scriptDataList.find(scriptData => scriptData.tag === tokenInfo.tokenType)
if (!token) {
setToast({
message: `tokenType ${tokenInfo.tokenType} is not found`,
})
return
}
typeHash = utils.computeScriptHash({
codeHash: token.codeHashes[0],
hashType: token.hashType,
args: tokenInfo.args,
})
}
const typeHash = utils.computeScriptHash({
codeHash: token.codeHashes[0],
hashType: token.hashType,
args: tokenInfo.args,
})

const commonInfo = {
symbol: tokenInfo.symbol,
Expand Down Expand Up @@ -292,7 +297,7 @@ export const SubmitTokenInfo = ({
}

return (
<CommonModal isOpen={isOpen} onClose={handleClose}>
<CommonModal isOpen onClose={handleClose}>
<div className={styles.modalWrapper}>
<div className={styles.contentWrapper}>
<div className={styles.modalTitle}>
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,8 @@
"1033": "UDT has no contact email",
"1034": "Token has expired",
"1035": "Token is not matched",
"1036": "Token is requested too frequently"
"1036": "Token is requested too frequently",
"1037": "Token is required to update udt info"
}
},
"pagination": {
Expand Down
7 changes: 4 additions & 3 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,9 +555,10 @@
"1031": "UDT 验证失败",
"1032": "未找到 UDT 验证",
"1033": "UDT 没有联系电子邮件",
"1034": "令牌已过期",
"1035": "令牌不匹配",
"1036": "请求令牌过于频繁"
"1034": "验证码已过期",
"1035": "验证码不匹配",
"1036": "请求验证码过于频繁",
"1037": "更新 UDT 信息需要验证码"
}
},
"pagination": {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Tokens/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ const Tokens: FC<{ isInscription?: boolean }> = ({ isInscription }) => {
onChange={setPage}
/>
</TokensPanel>
<SubmitTokenInfo isOpen={isSubmitTokenInfoModalOpen} onClose={() => setIsSubmitTokenInfoModalOpen(false)} />
{isSubmitTokenInfoModalOpen ? <SubmitTokenInfo onClose={() => setIsSubmitTokenInfoModalOpen(false)} /> : null}
</Content>
</>
)
Expand Down
1 change: 0 additions & 1 deletion src/pages/UDT/UDTComp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ export const UDTOverviewCard = ({
</Card>
{tokenInfo && isModifyTokenInfoModalOpen ? (
<SubmitTokenInfo
isOpen
onClose={() => setIsModifyTokenInfoModalOpen(false)}
initialInfo={tokenInfo}
onSuccess={refetchUDT}
Expand Down

0 comments on commit e5d8ebb

Please sign in to comment.