Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/feat/gas-account' into tmp/20240830
Browse files Browse the repository at this point in the history
  • Loading branch information
dmy147 committed Sep 3, 2024
2 parents ea94eea + 7892480 commit 8e92d86
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 37 deletions.
1 change: 1 addition & 0 deletions _raw/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
"watchUnavailableTip": "Watch-only address is not supported for Free Gas"
},
"gasAccount": {
"customRPC": "Not supported when using custom RPC",
"notEnough": "Gas balance is not enough",
"useGasAccount": "Use GasAccount",
"WalletConnectTips": "WalletConnect is not supported by GasAccount",
Expand Down
3 changes: 3 additions & 0 deletions src/ui/utils/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const formatTokenAmount = (
if (moreDecimalsWhenNotEnough && bn.lt(0.0001) && decimals < 8) {
realDecimals = 8;
}
if (moreDecimalsWhenNotEnough && bn.lt(0.00000001)) {
return '<0.00000001';
}
if (!split[1] || split[1].length < realDecimals) {
return splitNumberByStep(bn.toFixed());
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/AddressManagement/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ const AddressManagement = () => {
{enableSwitch
? t('page.manageAddress.current-address')
: t('page.manageAddress.address-management')}
<div className="bg-r-neutral-card2 rounded absolute top-20 right-0 w-[32px] h-[28px] flex items-center justify-center">
<div className="bg-r-neutral-card1 rounded absolute top-20 right-0 w-[32px] h-[28px] flex items-center justify-center">
<RcIconAddAddress
viewBox="0 0 20 20"
className={clsx(
Expand Down
5 changes: 4 additions & 1 deletion src/ui/views/Approval/components/FooterBar/FooterBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ interface Props extends Omit<ActionGroupProps, 'account'> {
isGasAccountLogin?: boolean;
isWalletConnect?: boolean;
gasAccountCanPay?: boolean;
noCustomRPC?: boolean;
}

const Wrapper = styled.section`
Expand Down Expand Up @@ -161,6 +162,7 @@ export const FooterBar: React.FC<Props> = ({
isGasAccountLogin,
isWalletConnect,
gasAccountCanPay,
noCustomRPC,
...props
}) => {
const [account, setAccount] = React.useState<Account>();
Expand Down Expand Up @@ -316,7 +318,7 @@ export const FooterBar: React.FC<Props> = ({
) : isWatchAddr ? null : (
<GasLessNotEnough
gasLessFailedReason={gasLessFailedReason}
gasAccountCost={gasAccountCost}
gasAccountCanPay={gasAccountCanPay}
onChangeGasAccount={onChangeGasAccount}
/>
)
Expand All @@ -327,6 +329,7 @@ export const FooterBar: React.FC<Props> = ({
gasAccountCost={gasAccountCost}
isGasAccountLogin={isGasAccountLogin}
isWalletConnect={isWalletConnect}
noCustomRPC={noCustomRPC}
/>
) : null}
</Wrapper>
Expand Down
19 changes: 10 additions & 9 deletions src/ui/views/Approval/components/FooterBar/GasLessComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,20 @@ export type GasLessConfig = {

export function GasLessNotEnough({
gasLessFailedReason,
gasAccountCost,
onChangeGasAccount,
gasAccountCanPay,
}: {
url?: string;
gasLessFailedReason?: string;
gasAccountCost?: GasAccountCheckResult;
onChangeGasAccount?: () => void;
gasAccountCanPay?: boolean;
}) {
const { t } = useTranslation();
const [
hoverGasLessFailedReason,
setHoverGasLessFailedReason,
] = React.useState(false);

const canUseGasAccount =
!!gasAccountCost?.is_gas_account &&
!!gasAccountCost?.balance_is_enough &&
!gasAccountCost?.chain_not_support;

return (
<div
className="security-level-tip bg-r-neutral-card2 text-r-neutral-card2 mt-[15px] items-center"
Expand All @@ -62,7 +57,7 @@ export function GasLessNotEnough({
{t('page.signFooterBar.gasAccount.notEnough')}
</span>

{canUseGasAccount ? (
{gasAccountCanPay ? (
<div
style={{
cursor: 'pointer',
Expand Down Expand Up @@ -360,15 +355,20 @@ export function GasAccountTips({
gasAccountCost,
isGasAccountLogin,
isWalletConnect,
noCustomRPC,
}: {
gasAccountCost?: GasAccountCheckResult;
isGasAccountLogin?: boolean;
isWalletConnect?: boolean;
noCustomRPC?: boolean;
}) {
const { t } = useTranslation();
const [tipPopupVisible, setTipPopupVisible] = useState(false);

const [tip, btnText] = useMemo(() => {
if (!noCustomRPC) {
return [t('page.signFooterBar.gasAccount.customRPC'), null];
}
if (isWalletConnect) {
return [t('page.signFooterBar.gasAccount.WalletConnectTips'), null];
}
Expand Down Expand Up @@ -400,7 +400,8 @@ export function GasAccountTips({
!isWalletConnect &&
isGasAccountLogin &&
gasAccountCost?.balance_is_enough &&
!gasAccountCost.chain_not_support
!gasAccountCost.chain_not_support &&
noCustomRPC
) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ interface Props extends Omit<ActionGroupProps, 'account'> {
isGasAccountLogin?: boolean;
isWalletConnect?: boolean;
gasAccountCanPay?: boolean;
noCustomRPC?: boolean;
}

const Wrapper = styled.section`
Expand Down Expand Up @@ -169,6 +170,7 @@ export const MiniFooterBar: React.FC<Props> = ({
isGasAccountLogin,
isWalletConnect,
gasAccountCanPay,
noCustomRPC,
task,
...props
}) => {
Expand Down Expand Up @@ -290,7 +292,7 @@ export const MiniFooterBar: React.FC<Props> = ({
) : isWatchAddr ? null : (
<GasLessNotEnough
gasLessFailedReason={gasLessFailedReason}
gasAccountCost={gasAccountCost}
gasAccountCanPay={gasAccountCanPay}
onChangeGasAccount={onChangeGasAccount}
/>
)
Expand All @@ -301,6 +303,7 @@ export const MiniFooterBar: React.FC<Props> = ({
gasAccountCost={gasAccountCost}
isGasAccountLogin={isGasAccountLogin}
isWalletConnect={isWalletConnect}
noCustomRPC={noCustomRPC}
/>
) : null}
</>
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/Approval/components/MiniSignTx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ export const MiniSignTx = ({
/>
</div>
}
noCustomRPC={noCustomRPC}
gasMethod={gasMethod}
gasAccountCost={gasAccountCost}
gasAccountCanPay={gasAccountCanPay}
Expand Down
1 change: 1 addition & 0 deletions src/ui/views/Approval/components/SignTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2034,6 +2034,7 @@ const SignTx = ({ params, origin }: SignTxProps) => {
isWatchAddr={
currentAccountType === KEYRING_TYPE.WatchAddressKeyring
}
noCustomRPC={noCustomRPC}
gasMethod={gasMethod}
gasAccountCost={gasAccountCost}
gasAccountCanPay={gasAccountCanPay}
Expand Down
39 changes: 22 additions & 17 deletions src/ui/views/Approval/components/TxComponents/GasSelectorHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,8 @@ const GasSelectorHeader = ({
const gasCostAmountStr = useMemo(() => {
return `${formatTokenAmount(
new BigNumber(modalExplainGas.gasCostAmount).toString(10),
6
6,
true
)} ${chain.nativeTokenSymbol}`;
}, [modalExplainGas?.gasCostAmount]);

Expand Down Expand Up @@ -791,8 +792,8 @@ const GasSelectorHeader = ({
</>
) : gasMethod === 'gasAccount' ? (
<div className="gas-selector-card-content-item relative">
<TooltipWithMagnetArrow
className="rectangle w-[max-content]"
<Tooltip
overlayClassName="rectangle"
title={
<>
<div>
Expand All @@ -817,13 +818,13 @@ const GasSelectorHeader = ({
</>
}
>
<div className="text-[16px] font-medium text-r-blue-default border-b border-dashed border-rabby-blue-disable">
<div className="text-[16px] font-medium text-r-blue-default">
{gasAccountCost?.gas_account_cost.total_cost} USD
</div>
</TooltipWithMagnetArrow>
</Tooltip>
</div>
) : (
<div className="gas-selector-card-content-item">
<div className="gas-selector-card-content-item relative">
<div
className={clsx(
'gas-selector-card-amount translate-y-1 flex items-center',
Expand All @@ -838,14 +839,14 @@ const GasSelectorHeader = ({
)}
>
{gasMethod ? (
<div className="truncate max-w-[180px] group">
<span className="hidden group-hover:inline">
{gasCostUsdStr}
</span>
<span className="group-hover:hidden">
{gasCostAmountStr}
</span>
</div>
<Tooltip
overlayClassName="rectangle"
title={`≈${gasCostUsdStr}`}
>
<div className="truncate max-w-[180px] group">
<span>{gasCostAmountStr}</span>
</div>
</Tooltip>
) : (
<span
className="truncate max-w-[110px]"
Expand Down Expand Up @@ -1137,10 +1138,14 @@ const GasMethod = (props: {
}) => {
const { active, onChange, ActiveComponent, BlurComponent, tips } = props;
return (
<TooltipWithMagnetArrow
className="rectangle w-[max-content]"
<Tooltip
overlayClassName="rectangle"
title={tips}
visible={tips ? undefined : false}
placement="topLeft"
align={{
offset: [-4, 0],
}}
>
<div
className={clsx(
Expand All @@ -1160,7 +1165,7 @@ const GasMethod = (props: {
)}
/>
</div>
</TooltipWithMagnetArrow>
</Tooltip>
);
};

Expand Down
9 changes: 5 additions & 4 deletions src/ui/views/GasAccount/components/GasAccountTxPopups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import PNGDepositTip from '@/ui/assets/gas-account/gas-account-deposit-tip.png';
import { GasAccountBlueLogo } from './GasAccountBlueLogo';
import { ReactComponent as RcIconQuoteStart } from '@/ui/assets/gas-account/quote-start.svg';
import { ReactComponent as RcIconQuoteEnd } from '@/ui/assets/gas-account/quote-end.svg';
import { GasAccountWrapperBg } from './WrapperBg';

const GasAccountDepositTipContent = ({ onClose }: { onClose: () => void }) => {
const { t } = useTranslation();

return (
<div className="w-full h-full flex flex-col justify-center items-center">
<GasAccountWrapperBg className="w-full h-full flex flex-col justify-center items-center">
<div className="text-20 font-medium text-r-neutral-title1 my-24">
{t('page.gasAccount.GasAccountDepositTipPopup.title')}
</div>
Expand All @@ -29,7 +30,7 @@ const GasAccountDepositTipContent = ({ onClose }: { onClose: () => void }) => {
{t('page.gasAccount.GasAccountDepositTipPopup.gotIt')}
</Button>
</div>
</div>
</GasAccountWrapperBg>
);
};

Expand All @@ -56,7 +57,7 @@ const GasAccountLoginTipContent = ({ onClose }: { onClose: () => void }) => {
const { t } = useTranslation();

return (
<div className="w-full h-full flex flex-col justify-center items-center">
<GasAccountWrapperBg className="w-full h-full flex flex-col justify-center items-center">
<GasAccountBlueLogo className="w-[60px] h-[60px] my-24" />
<div className="relative mb-[16px] text-18 font-medium text-r-blue-default">
<RcIconQuoteStart
Expand Down Expand Up @@ -84,7 +85,7 @@ const GasAccountLoginTipContent = ({ onClose }: { onClose: () => void }) => {
{t('page.gasAccount.GasAccountDepositTipPopup.gotIt')}
</Button>
</div>
</div>
</GasAccountWrapperBg>
);
};

Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/GasAccount/components/LoginPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const GasAccountLoginContent = ({ onClose }: { onClose: () => void }) => {
block
size="large"
type="primary"
className="h-[44px] text-r-neutral-title2 text-15 font-medium"
className="h-[48px] text-r-neutral-title2 text-15 font-medium"
>
{t('global.Confirm')}
</Button>
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/GasAccount/hooks/checkTxs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const useGasAccountTxsCheck = ({
setIsGasAccountLogin(false);
}
return wallet.openapi.checkGasAccountTxs({
sig: sig!,
sig: sig || '',
account_id: accountId!,
tx_list: txs,
});
Expand Down
8 changes: 7 additions & 1 deletion src/ui/views/GasAccount/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,10 @@ export const useGasAccountHistory = () => {
reloadDeps: [sig],
isNoMore(data) {
if (data) {
return !(!!data?.rechargeList && data?.rechargeList?.length > 0);
return (
data.totalCount <=
(data.list.length || 0) + (data?.rechargeList?.length || 0)
);
}
return true;
},
Expand Down Expand Up @@ -191,9 +194,12 @@ export const useGasAccountHistory = () => {

const [inViewport] = useInViewport(ref);

console.log('inViewport', inViewport, noMore, loadingMore);

useEffect(() => {
if (!noMore && inViewport && !loadingMore && loadMore) {
loadMore();
console.log('loadMore');
}
}, [inViewport, loadMore, loading, loadingMore, noMore]);

Expand Down
5 changes: 4 additions & 1 deletion src/ui/views/GasAccount/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ const GasAccountInner = () => {
/>
<GasAccountLogoutPopup
visible={logoutVisible}
onCancel={() => setLogoutVisible(false)}
onCancel={() => {
gotoDashboard();
setLogoutVisible(false);
}}
/>
<GasAccountDepositPopup
visible={depositVisible}
Expand Down

0 comments on commit 8e92d86

Please sign in to comment.