diff --git a/.github/workflows/package_for_test.yml b/.github/workflows/package_for_test.yml index e8e7677cca..150df84948 100644 --- a/.github/workflows/package_for_test.yml +++ b/.github/workflows/package_for_test.yml @@ -53,19 +53,11 @@ jobs: uses: actions/checkout@v3 if: ${{ github.event_name == 'push' }} - - name: Get PR Branch - if: github.event_name == 'issue_comment' - id: comment-branch - uses: yanguoyu/pull-request-comment-branch@v2.1.0-beta - with: - repo_token: ${{ secrets.GITHUB_TOKEN }} - - name: Checkout for PR uses: actions/checkout@v3 if: ${{ github.event_name == 'issue_comment' }} with: - repository: ${{ steps.comment-branch.outputs.head_owner }}/${{ steps.comment-branch.outputs.head_repo }} - ref: ${{ steps.comment-branch.outputs.head_ref }} + ref: refs/pull/${{ github.event.issue.number }}/merge - name: Setup Node uses: actions/setup-node@v3 diff --git a/packages/neuron-ui/src/components/MultisigAddress/index.tsx b/packages/neuron-ui/src/components/MultisigAddress/index.tsx index 96e6d5d3b6..d7aad06774 100644 --- a/packages/neuron-ui/src/components/MultisigAddress/index.tsx +++ b/packages/neuron-ui/src/components/MultisigAddress/index.tsx @@ -119,12 +119,11 @@ const MultisigAddress = () => { ) const listNoBalanceActionOptions = useMemo( () => - tableActions.map(item => ({ + listActionOptions.map(item => ({ ...item, - label: t(`multisig-address.table.actions.${item.key}`), - disabled: item.key === 'send', + disabled: item.disabled || item.key === 'send', })), - [t] + [listActionOptions] ) const { keywords, onChange, onBlur } = useSearch(clearSelected, onFilterConfig) diff --git a/packages/neuron-ui/src/components/OfflineSignDialog/index.tsx b/packages/neuron-ui/src/components/OfflineSignDialog/index.tsx index f64275da71..ee497aeb65 100644 --- a/packages/neuron-ui/src/components/OfflineSignDialog/index.tsx +++ b/packages/neuron-ui/src/components/OfflineSignDialog/index.tsx @@ -16,7 +16,7 @@ import { } from 'states' import { OfflineSignJSON, signAndExportTransaction, OfflineSignType } from 'services/remote' import { PasswordIncorrectException } from 'exceptions' -import styles from '../PasswordRequest/passwordRequest.module.scss' +import styles from './offlineSignDialog.module.scss' interface SignDialogProps { isBroadcast: boolean @@ -199,7 +199,15 @@ const OfflineSignDialog = ({ isBroadcast, wallet, offlineSignJSON, onDismiss }: } return ( - + void + isExperimental?: boolean } enum PriceTypeEnum { Custom = 'custom', @@ -25,7 +26,12 @@ enum PriceTypeEnum { const DEFAULT_PRICE_ARRAY = ['1000', '2000', '3000'] const DEFAULT_COUNT_DOWN = 30 -const PricePanel: React.FunctionComponent = ({ price, field, onPriceChange }: PricePanelProps) => { +const PricePanel: React.FunctionComponent = ({ + price, + field, + onPriceChange, + isExperimental, +}: PricePanelProps) => { const [t] = useTranslation() const [type, setType] = useState(PriceTypeEnum.Standard) const [feeRateValueArray, setFeeRateValueArray] = useState([]) @@ -35,7 +41,9 @@ const PricePanel: React.FunctionComponent = ({ price, field, on const { app: { send = appState.send }, wallet: { id: walletID = '' }, + experimental, } = useGlobalState() + const { countDown, suggestFeeRate } = useGetCountDownAndFeeRateStats({ seconds: DEFAULT_COUNT_DOWN }) const isStandard = type === PriceTypeEnum.Standard @@ -108,10 +116,16 @@ const PricePanel: React.FunctionComponent = ({ price, field, on ) useEffect(() => { - useGetBatchGeneratedTx({ walletID, items: send.outputs, priceArray }).then(res => { - setFeeRateValueArray(res) - }) - }, [send.outputs, priceArray]) + if (isExperimental && experimental) { + batchGenerateExperimental(experimental, priceArray).then(res => { + setFeeRateValueArray(res) + }) + } else { + useGetBatchGeneratedTx({ walletID, items: send.outputs, priceArray }).then(res => { + setFeeRateValueArray(res) + }) + } + }, [send.outputs, priceArray, isExperimental, experimental, batchGenerateExperimental, setFeeRateValueArray]) useEffect(() => { if (suggestFeeRate === 0) { @@ -141,7 +155,7 @@ const PricePanel: React.FunctionComponent = ({ price, field, on onKeyDown={() => {}} type="button" > - + {isStandard ? ( diff --git a/packages/neuron-ui/src/components/SUDTSend/hooks.ts b/packages/neuron-ui/src/components/SUDTSend/hooks.ts index 3880b155bb..14c84f6cc9 100644 --- a/packages/neuron-ui/src/components/SUDTSend/hooks.ts +++ b/packages/neuron-ui/src/components/SUDTSend/hooks.ts @@ -4,15 +4,8 @@ import { SUDTAccount } from 'components/SUDTAccountList' import { DEFAULT_SUDT_FIELDS } from 'utils/const' import { generateChequeTransaction, generateSUDTTransaction, getHoldSUDTCellCapacity } from 'services/remote' import { AppActions, useDispatch } from 'states' - -export enum SendType { - secp256Cheque = 'cheque', - secp256NewCell = 'secp256NewCell', - acpExistCell = 'acpExistCell', - acpNewCell = 'acpNewCell', - unknowNewCell = 'unknowNewCell', - sendCKB = 'sendCKB', -} +import { ControllerResponse } from 'services/remote/remoteApiWrapper' +import { SendType } from 'utils/enums' export enum AddressLockType { secp256 = 'secp256', @@ -152,6 +145,29 @@ export function getGenerator(sendType?: SendType) { return generateSUDTTransaction } +export async function batchGenerateExperimental(experimental: State.Experimental, priceArray: string[]) { + if (experimental?.params) { + const { params } = experimental + const generator = getGenerator(params.sendType) + const requestArray = priceArray.map(itemPrice => generator({ ...params, feeRate: itemPrice })) + const allPromiseResult = await Promise.allSettled(requestArray) + const resList = allPromiseResult.map( + (batchItem: PromiseSettledResult>, index: number) => ({ + feeRateValue: priceArray[index], + feeValue: + batchItem.status === 'fulfilled' && isSuccessResponse(batchItem.value) && batchItem.value.result + ? batchItem.value.result.fee + : '0', + }) + ) + return resList + } + return priceArray.map((_, index: number) => ({ + feeRateValue: priceArray[index], + feeValue: '0', + })) +} + export function useOnSubmit({ isSubmittable, accountType, diff --git a/packages/neuron-ui/src/components/SUDTSend/index.tsx b/packages/neuron-ui/src/components/SUDTSend/index.tsx index 1ab8aa374f..bd2869da8d 100644 --- a/packages/neuron-ui/src/components/SUDTSend/index.tsx +++ b/packages/neuron-ui/src/components/SUDTSend/index.tsx @@ -31,17 +31,10 @@ import { validateAmountRange, CONSTANTS, } from 'utils' +import { SendType } from 'utils/enums' import { AmountNotEnoughException, isErrorWithI18n } from 'exceptions' import { getDisplayName, getDisplaySymbol } from 'components/UANDisplay' -import { - AddressLockType, - SendType, - getGenerator, - useAddressLockType, - useOnSubmit, - useOptions, - useSendType, -} from './hooks' +import { AddressLockType, getGenerator, useAddressLockType, useOnSubmit, useOptions, useSendType } from './hooks' import styles from './sUDTSend.module.scss' const { INIT_SEND_PRICE, DEFAULT_SUDT_FIELDS, HIDE_BALANCE } = CONSTANTS @@ -162,9 +155,9 @@ const SUDTSend = () => { { label: t('s-udt.send.title'), link: RoutePath.SUDTSend }, ] - const fields: { key: Fields.Address | Fields.Amount; label: string }[] = [ - { key: Fields.Address, label: t('s-udt.send.address') }, - { key: Fields.Amount, label: t('s-udt.send.amount') }, + const fields: { key: Fields.Address | Fields.Amount; label: string; placeholder: string }[] = [ + { key: Fields.Address, label: t('s-udt.send.address'), placeholder: t('s-udt.send.address-placeholder') }, + { key: Fields.Amount, label: t('s-udt.send.amount'), placeholder: t('s-udt.send.amount-placeholder') }, ] const errors: { [Fields.Address]: string; [Fields.Amount]: string } = useMemo(() => { @@ -247,7 +240,10 @@ const SUDTSend = () => { generator(params) .then(res => { if (isSuccessResponse(res)) { - globalDispatch({ type: AppActions.UpdateExperimentalParams, payload: { tx: res.result } }) + globalDispatch({ + type: AppActions.UpdateExperimentalParams, + payload: { tx: res.result, params: { ...params, sendType } }, + }) return } throw new Error(typeof res.message === 'string' ? res.message : res.message.content) @@ -298,6 +294,16 @@ const SUDTSend = () => { [dispatch, setRemoteError] ) + const handleCheckbox = useCallback( + (e: React.ChangeEvent) => { + if (options && options.length) { + const { checked } = e.target + onChangeSendType(checked ? options[0].key : undefined) + } + }, + [onChangeSendType, options] + ) + const onToggleSendingAll = useCallback(() => { dispatch({ type: Fields.SendAll, payload: !sendState.sendAll }) }, [dispatch, sendState.sendAll]) @@ -361,7 +367,7 @@ const SUDTSend = () => {
{fields.map(field => { return ( - <> +
{ key={field.label} field={field.key} onChange={onInput} - rows={field.key === Fields.Address ? 2 : 1} + rows={field.key === Fields.Address && sendState.address ? 2 : 1} suffix={ field.key === Fields.Amount ? (
) })}
@@ -434,10 +447,11 @@ const SUDTSend = () => { field={Fields.Description} onChange={onInput} error={remoteError} + placeholder={t('s-udt.send.description-placeholder')} />
- +
diff --git a/packages/neuron-ui/src/components/SUDTSend/sUDTSend.module.scss b/packages/neuron-ui/src/components/SUDTSend/sUDTSend.module.scss index 6a3579fbc3..865fff309f 100644 --- a/packages/neuron-ui/src/components/SUDTSend/sUDTSend.module.scss +++ b/packages/neuron-ui/src/components/SUDTSend/sUDTSend.module.scss @@ -72,6 +72,7 @@ $bottomHeight: 186px; margin-top: 16px; padding: 20px 16px 16px; @include card; + @include checkbox; .address { font-family: 'JetBrains Mono'; } diff --git a/packages/neuron-ui/src/components/SendFromMultisigDialog/sendFromMultisigDialog.module.scss b/packages/neuron-ui/src/components/SendFromMultisigDialog/sendFromMultisigDialog.module.scss index 3e2306c2f9..06f99f3ddc 100644 --- a/packages/neuron-ui/src/components/SendFromMultisigDialog/sendFromMultisigDialog.module.scss +++ b/packages/neuron-ui/src/components/SendFromMultisigDialog/sendFromMultisigDialog.module.scss @@ -104,6 +104,7 @@ .sendItem { & > div { + width: 228px; input { width: 125px !important; height: 56px !important; diff --git a/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx b/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx index 5183d88508..01cf6ca9cb 100644 --- a/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx +++ b/packages/neuron-ui/src/components/TransactionFeePanel/index.tsx @@ -7,19 +7,21 @@ interface TransactionFeeProps { fee: string price: string onPriceChange: (value: string) => void + isExperimental?: boolean } const TransactionFeePanel: React.FunctionComponent = ({ price, fee, onPriceChange, + isExperimental, }: TransactionFeeProps) => { const [t] = useTranslation() return (
- +
) } diff --git a/packages/neuron-ui/src/locales/en.json b/packages/neuron-ui/src/locales/en.json index 1de6326692..1bbf41e751 100644 --- a/packages/neuron-ui/src/locales/en.json +++ b/packages/neuron-ui/src/locales/en.json @@ -950,8 +950,11 @@ "send": { "title": "Send", "address": "Send to", + "address-placeholder": "Please input address", "amount": "Amount", + "amount-placeholder": "Please input amount", "description": "Description", + "description-placeholder": "Please input description, optional", "submit": "Submit", "click-to-edit": "Click to edit", "cheque-address-hint": { diff --git a/packages/neuron-ui/src/locales/zh-tw.json b/packages/neuron-ui/src/locales/zh-tw.json index 4abbab3527..a68ed4f85a 100644 --- a/packages/neuron-ui/src/locales/zh-tw.json +++ b/packages/neuron-ui/src/locales/zh-tw.json @@ -920,8 +920,11 @@ "send": { "title": "轉帳", "address": "收款地址", + "address-placeholder": "請輸入收款地址", "amount": "转账金額", + "amount-placeholder": "請輸入转账金額", "description": "備註", + "description-placeholder": "請輸入转账備註,選填", "submit": "提交", "click-to-edit": "點擊編輯", "cheque-address-hint": { diff --git a/packages/neuron-ui/src/locales/zh.json b/packages/neuron-ui/src/locales/zh.json index 584a014e26..c7b17914c2 100644 --- a/packages/neuron-ui/src/locales/zh.json +++ b/packages/neuron-ui/src/locales/zh.json @@ -942,8 +942,11 @@ "send": { "title": "转账", "address": "收款地址", + "address-placeholder": "请输入收款地址", "amount": "转账金额", + "amount-placeholder": "请输入转账金额", "description": "备注", + "description-placeholder": "请输入转账备注,选填", "submit": "提交", "click-to-edit": "点击编辑", "cheque-address-hint": { diff --git a/packages/neuron-ui/src/states/stateProvider/reducer.ts b/packages/neuron-ui/src/states/stateProvider/reducer.ts index 7f3208f7cc..4e5ccf0415 100644 --- a/packages/neuron-ui/src/states/stateProvider/reducer.ts +++ b/packages/neuron-ui/src/states/stateProvider/reducer.ts @@ -93,7 +93,7 @@ export type StateAction = | { type: AppActions.ToggleAllNotificationVisibility; payload?: boolean } | { type: AppActions.ToggleIsAllowedToFetchList; payload?: boolean } | { type: AppActions.Ignore; payload?: any } - | { type: AppActions.UpdateExperimentalParams; payload: { tx: any; assetAccount?: any } | null } + | { type: AppActions.UpdateExperimentalParams; payload: State.Experimental | null } | { type: AppActions.UpdateLoadedTransaction; payload: { filePath?: string; json: OfflineSignJSON } } | { type: AppActions.SetPageNotice; payload?: State.PageNotice } | { type: AppActions.HideWaitForFullySynced } diff --git a/packages/neuron-ui/src/types/App/index.d.ts b/packages/neuron-ui/src/types/App/index.d.ts index fb4a58a72b..a1cc5666d3 100644 --- a/packages/neuron-ui/src/types/App/index.d.ts +++ b/packages/neuron-ui/src/types/App/index.d.ts @@ -281,6 +281,29 @@ declare namespace State { errorMsg: string } + enum SendType { + secp256Cheque = 'cheque', + secp256NewCell = 'secp256NewCell', + acpExistCell = 'acpExistCell', + acpNewCell = 'acpNewCell', + unknowNewCell = 'unknowNewCell', + sendCKB = 'sendCKB', + } + + interface Experimental { + tx: any + assetAccount?: any + params?: { + assetAccountID: string + walletID: string + address: string + amount: string + feeRate: string + description: string + sendType?: SendType + } + } + interface AppWithNeuronWallet { app: App chain: Chain @@ -289,7 +312,7 @@ declare namespace State { nervosDAO: NervosDAO updater: AppUpdater sUDTAccounts: SUDTAccount[] - experimental: { tx: any; assetAccount?: any } | null + experimental: Experimental | null } } diff --git a/packages/neuron-ui/src/utils/enums.ts b/packages/neuron-ui/src/utils/enums.ts index ae795d1f1e..91406db039 100644 --- a/packages/neuron-ui/src/utils/enums.ts +++ b/packages/neuron-ui/src/utils/enums.ts @@ -215,3 +215,12 @@ export enum AccountType { CKB, SUDT, } + +export enum SendType { + secp256Cheque = 'cheque', + secp256NewCell = 'secp256NewCell', + acpExistCell = 'acpExistCell', + acpNewCell = 'acpNewCell', + unknowNewCell = 'unknowNewCell', + sendCKB = 'sendCKB', +}