Skip to content

Commit

Permalink
fix: 244
Browse files Browse the repository at this point in the history
  • Loading branch information
devchenyan committed Jul 30, 2023
1 parent 6e50be2 commit b79ebb4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 6 deletions.
18 changes: 17 additions & 1 deletion packages/neuron-ui/src/components/SUDTAccountList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ReactComponent as EyesClose } from 'widgets/Icons/EyesClose.svg'
import { ReactComponent as Search } from 'widgets/Icons/SearchIcon.svg'
import { ReactComponent as AddSimple } from 'widgets/Icons/AddSimple.svg'
import SUDTReceiveDialog, { DataProps } from 'components/SUDTReceiveDialog'
import Toast from 'widgets/Toast'
import TableNoData from 'widgets/Icons/TableNoData.png'

import { useState as useGlobalState, useDispatch, AppActions, NeuronWalletActions } from 'states'
Expand Down Expand Up @@ -52,6 +53,7 @@ const SUDTAccountList = () => {
const isMainnet = isMainnetUtil(networks, networkID)
const [receiveData, setReceiveData] = useState<DataProps | null>(null)
const [showBalance, setShowBalance] = useState(true)
const [notice, setNotice] = useState('')

const existingAccountNames = sUDTAccounts.filter(acc => acc.accountName).map(acc => acc.accountName || '')

Expand Down Expand Up @@ -162,7 +164,7 @@ const SUDTAccountList = () => {
setDialog(null)
}, [setDialog])

const handleCreateAccount = useOnGenerateNewAccountTransaction({
const createAccount = useOnGenerateNewAccountTransaction({
walletId,
dispatch,
onGenerated: onTransactionGenerated,
Expand Down Expand Up @@ -206,6 +208,7 @@ const SUDTAccountList = () => {
if (isSuccessResponse(res)) {
fetchAndUpdateList()
setDialog(null)
setNotice(t('s-udt.edit-account-success'))
return true
}
throw new Error(typeof res.message === 'string' ? res.message : res.message.content)
Expand All @@ -222,6 +225,17 @@ const SUDTAccountList = () => {
}
: undefined

const handleCreateAccount = useCallback(
async (info: TokenInfo) => {
const isSuccess = await createAccount(info)
if (isSuccess) {
setNotice(t('s-udt.create-account-success'))
}
return isSuccess
},
[createAccount, setNotice]
)

return (
<PageContainer
head={
Expand Down Expand Up @@ -281,6 +295,8 @@ const SUDTAccountList = () => {
isMainnet={isMainnet}
/>
) : null}

<Toast content={notice} onDismiss={() => setNotice('')} />
</div>
</PageContainer>
)
Expand Down
19 changes: 18 additions & 1 deletion packages/neuron-ui/src/components/SUDTAccountPile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next'
import SUDTAvatar from 'widgets/SUDTAvatar'
import { HIDE_BALANCE, DEFAULT_SUDT_FIELDS } from 'utils/const'
import { sudtValueToAmount } from 'utils/formatters'
import Tooltip from 'widgets/Tooltip'
import { ReactComponent as Send } from 'widgets/Icons/SendStroke.svg'
import { ReactComponent as Receive } from 'widgets/Icons/ReceiveStroke.svg'
import { ReactComponent as ArrowOpenRight } from 'widgets/Icons/ArrowOpenRight.svg'
Expand Down Expand Up @@ -35,6 +36,16 @@ const SUDTAccountPile = ({
const isCKB = DEFAULT_SUDT_FIELDS.CKBTokenId === tokenId
const disabled = !isCKB && !decimal

const balanceText = sudtValueToAmount(balance, decimal)
let overBalanceText = ''

if (Number(decimal) > 8) {
const [integer, radix] = balanceText.split('.')
if (radix && radix.length > 8) {
overBalanceText = `${integer}.${radix.slice(0, 8)}`
}
}

return (
<div className={styles.container}>
<SUDTAvatar type="logo" />
Expand All @@ -50,7 +61,13 @@ const SUDTAccountPile = ({
</span>
</div>
<div className={styles.balance}>
{showBalance ? sudtValueToAmount(balance, decimal) || '--' : HIDE_BALANCE}
{overBalanceText && showBalance ? (
<Tooltip tipClassName={styles.tip} placement="top" tip={<span>{balanceText}</span>} showTriangle>
{overBalanceText}...
</Tooltip>
) : (
<span>{showBalance ? balanceText || '--' : HIDE_BALANCE}</span>
)}
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@
@include text-overflow-ellipsis;
}
}
.tip {
margin-top: -8px;
margin-left: -20px;
}
.balance {
margin-top: 8px;
text-overflow: ellipsis;
font-weight: 500;
font-size: 16px;
line-height: 22px;
Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@
"115": "You need more capacities for change (more than 61 CKBytes), or click 'Max' button to send all your balance.",
"201": "$t(messages.fields.{{fieldName}}) is required.",
"202": "$t(messages.fields.{{fieldName}}) is used.",
"203": "$t(messages.fields.{{fieldName}}) is too long, it should be shorter than or equal to {{length}}.",
"203": "$t(messages.fields.{{fieldName}}) should be shorter than or equal to {{length}}",
"204": "$t(messages.fields.{{fieldName}}) is too short, it should be longer than or equal to {{length}}.",
"205": "$t(messages.fields.{{fieldName}}) {{fieldValue}} is invalid.",
"206": "$t(messages.fields.{{fieldName}}) is invalid, please enter the $t(messages.fields.{{fieldName}}) with no more than {{length}} decimal places.",
Expand Down Expand Up @@ -918,6 +918,8 @@
"view-in-explorer": "Explorer"
},
"s-udt": {
"edit-account-success": "Edit account information successfully",
"create-account-success": "Asset account created successfully",
"account-list": {
"title": "Asset Accounts",
"no-asset-accounts": "No sUDT asset has been detected",
Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/locales/zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
"115": "您需要有足夠的餘額來支付找零(大于 61 CKBytes),或者點擊 'Max' 按鈕發送全部餘額。",
"201": "缺少$t(messages.fields.{{fieldName}})。",
"202": "$t(messages.fields.{{fieldName}}) {{fieldValue}} 已被使用。",
"203": "$t(messages.fields.{{fieldName}})太長,其長度應不超過 {{length}}",
"203": "$t(messages.fields.{{fieldName}})長度最大不超過{{length}}字符",
"204": "$t(messages.fields.{{fieldName}}) {{fieldValue}} 太短,其長度應不小於 {{length}}。",
"205": "$t(messages.fields.{{fieldName}}) {{fieldValue}} 無效。",
"206": "$t(messages.fields.{{fieldName}}) {{fieldValue}} 無效,其小數位應不超過 {{length}}比特。",
Expand Down Expand Up @@ -889,6 +889,8 @@
"view-in-explorer": "瀏覽器"
},
"s-udt": {
"edit-account-success": "編輯賬戶信息成功",
"create-account-success": "創建資產賬戶成功",
"account-list": {
"title": "資產賬戶",
"no-asset-accounts": "尚未檢索到您持有的 sUDT 資產",
Expand Down
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@
"115": "您需要有足够的余额来支付找零(大于 61 CKBytes),或者点击 'Max' 按钮发送全部余额。",
"201": "缺少$t(messages.fields.{{fieldName}})。",
"202": "$t(messages.fields.{{fieldName}}) {{fieldValue}} 已被使用。",
"203": "$t(messages.fields.{{fieldName}})太长, 其长度应不超过 {{length}}",
"203": "$t(messages.fields.{{fieldName}})长度最大不超过{{length}}个字符",
"204": "$t(messages.fields.{{fieldName}}) {{fieldValue}} 太短, 其长度应不小于 {{length}}。",
"205": "$t(messages.fields.{{fieldName}}) {{fieldValue}} 无效。",
"206": "$t(messages.fields.{{fieldName}}) {{fieldValue}} 无效, 其小数位应不超过 {{length}} 位。",
Expand Down Expand Up @@ -911,6 +911,8 @@
"view-in-explorer": "浏览器"
},
"s-udt": {
"edit-account-success": "编辑账户信息成功",
"create-account-success": "创建资产账户成功",
"account-list": {
"title": "资产账户",
"no-asset-accounts": "尚未检索到您持有的 sUDT 资产",
Expand Down

0 comments on commit b79ebb4

Please sign in to comment.