Skip to content

Commit

Permalink
feat: add loading ui
Browse files Browse the repository at this point in the history
  • Loading branch information
jinoosss committed Jan 13, 2025
1 parent dab579b commit 5c5dd19
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ describe('ApproveTransaction Component', () => {
return;
},
useNetworkFeeReturn: {
isFetchedPriceTiers: true,
currentGasPrice: {
amount: '0.0048',
denom: 'GNOT',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { View } from '@components/atoms';
import { SkeletonBoxStyle, View } from '@components/atoms';
import mixins from '@styles/mixins';
import { fonts, getTheme } from '@styles/theme';
import styled from 'styled-components';

export const NetworkFeeItemSkeletonBox = styled(SkeletonBoxStyle)`
${mixins.flex({ align: 'flex-start' })};
width: 55px;
height: 14px;
align-self: center;
`;

export const NetworkFeeSettingItemWrapper = styled(View)`
${mixins.flex({ direction: 'row', align: 'normal', justify: 'space-between' })};
display: flex;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { NetworkFeeSettingInfo, NetworkFeeSettingType } from '@types';
import React, { useMemo } from 'react';
import { TokenBalance } from '../token-balance';
import { NetworkFeeSettingItemWrapper } from './network-fee-setting-item.styles';
import {
NetworkFeeItemSkeletonBox,
NetworkFeeSettingItemWrapper,
} from './network-fee-setting-item.styles';

export interface NetworkFeeSettingItemProps {
selected: boolean;
isLoading: boolean;
select: () => void;
info: NetworkFeeSettingInfo;
}
Expand All @@ -17,6 +21,7 @@ const networkFeeSettingTypeNames: { [key in NetworkFeeSettingType]: string } = {

const NetworkFeeSettingItem: React.FC<NetworkFeeSettingItemProps> = ({
selected,
isLoading,
info,
select,
}) => {
Expand Down Expand Up @@ -51,6 +56,16 @@ const NetworkFeeSettingItem: React.FC<NetworkFeeSettingItemProps> = ({
select();
};

if (isLoading) {
return (
<NetworkFeeSettingItemWrapper className='loading'>
<span className='title'>{'Loading...'}</span>

<NetworkFeeItemSkeletonBox />
</NetworkFeeSettingItemWrapper>
);
}

return (
<NetworkFeeSettingItemWrapper className={selected ? 'selected' : ''} onClick={onClickItem}>
<span className='title'>{settingTypeName}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('NetworkFeeSetting Component', () => {
it('NetworkFeeSetting render', () => {
const args: NetworkFeeSettingProps = {
gasPriceRatio: '1.5',
isFetchedPriceTiers: true,
setGasPriceRatio: () => {
return;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BigNumber from 'bignumber.js';
import { NetworkFeeSettingWrapper } from './network-fee-setting.styles';

export interface NetworkFeeSettingProps {
isFetchedPriceTiers: boolean;
changedGasPrice: GasPrice | null;
networkFeeSettingType: NetworkFeeSettingType;
setNetworkFeeSetting: (settingInfo: NetworkFeeSettingInfo) => void;
Expand All @@ -27,6 +28,7 @@ const settingTypesOfList: NetworkFeeSettingType[] = [
];

const NetworkFeeSetting: React.FC<NetworkFeeSettingProps> = ({
isFetchedPriceTiers,
changedGasPrice,
networkFeeSettingType,
setNetworkFeeSetting,
Expand Down Expand Up @@ -82,6 +84,7 @@ const NetworkFeeSetting: React.FC<NetworkFeeSettingProps> = ({
<NetworkFeeSettingItem
key={index}
selected={isSelected(settingInfo)}
isLoading={!isFetchedPriceTiers}
info={settingInfo}
select={(): void => setNetworkFeeSetting(settingInfo)}
/>
Expand Down
7 changes: 6 additions & 1 deletion packages/adena-extension/src/hooks/wallet/use-network-fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useGetGasPriceTires } from './transaction-gas/use-get-gas-price';
import { useGetSingleEstimateGas } from './transaction-gas/use-get-single-estimate-gas';

export interface UseNetworkFeeReturn {
isFetchedPriceTiers: boolean;
currentGasPrice: GasPrice | null;
currentGasPriceRawAmount: number;
changedGasPrice: GasPrice | null;
Expand Down Expand Up @@ -36,7 +37,10 @@ export const useNetworkFee = (

const { data: gasPriceTiers } = useGetGasPriceTires(gasPriceRatio);

const { data: estimatedGasPriceTiers } = useGetEstimateGas(document, gasPriceTiers);
const { data: estimatedGasPriceTiers, isFetched: isFetchedPriceTiers } = useGetEstimateGas(
document,
gasPriceTiers,
);

const { data: estimatedDefaultGasPrice = null } = useGetSingleEstimateGas(document, {
enabled: !selectedTier,
Expand Down Expand Up @@ -133,6 +137,7 @@ export const useNetworkFee = (
}, [changedSettingType]);

return {
isFetchedPriceTiers,
currentGasPrice,
currentGasPriceRawAmount,
changedGasPrice,
Expand Down

0 comments on commit 5c5dd19

Please sign in to comment.