Skip to content

Commit 7e40943

Browse files
committed
fix: fix a minor issues
1 parent 17bb288 commit 7e40943

File tree

19 files changed

+129
-174
lines changed

19 files changed

+129
-174
lines changed

packages/adena-extension/src/components/molecules/network-fee-setting-item/network-fee-setting-item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const NetworkFeeSettingItem: React.FC<NetworkFeeSettingItemProps> = ({
3535
[info.settingType],
3636
);
3737

38-
const hasGasInfo = !!info && !!info.gasInfo;
38+
const hasGasInfo = !!info && !!info.gasInfo && !info.gasInfo.hasError;
3939

4040
const gasInfoAmount = useMemo(() => {
4141
if (!hasGasInfo || !info?.gasInfo) {

packages/adena-extension/src/components/pages/router/side-menu-layout/side-menu-container.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const SideMenuContainer: React.FC<SideMenuContainerProps> = ({ open, setOpen })
3232
const { currentNetwork, scannerParameters } = useNetwork();
3333
const { accountNames } = useAccountName();
3434
const { accounts, loadAccounts } = useLoadAccounts();
35-
const { accountNativeBalanceMap, refetchAccountNativeBalanceMap } = useTokenBalance();
35+
const { accountNativeBalanceMap } = useTokenBalance();
3636
const [locked, setLocked] = useState(true);
3737
const { currentAccount } = useCurrentAccount();
3838
const [latestAccountInfos, setLatestAccountInfos] = useState<SideMenuAccountInfo[]>([]);
@@ -144,12 +144,6 @@ const SideMenuContainer: React.FC<SideMenuContainerProps> = ({ open, setOpen })
144144
}
145145
}, [sideMenuAccounts]);
146146

147-
useEffect(() => {
148-
if (open && sideMenuAccounts.length > 0) {
149-
refetchAccountNativeBalanceMap();
150-
}
151-
}, [open, sideMenuAccounts]);
152-
153147
return (
154148
<SideMenu
155149
scannerUrl={scannerUrl}

packages/adena-extension/src/components/pages/router/side-menu/side-menu.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ const SideMenu: React.FC<SideMenuProps> = ({
3030
const moveGnoscan = useCallback(
3131
(address: string) => {
3232
const openLinkUrl = scannerQueryString
33-
? `${scannerUrl}/accounts/${address}?${scannerQueryString}`
34-
: `${scannerUrl}/accounts/${address}`;
33+
? `${scannerUrl}/account/${address}?${scannerQueryString}`
34+
: `${scannerUrl}/account/${address}`;
3535
openLink(openLinkUrl);
3636
},
3737
[openLink],

packages/adena-extension/src/hooks/use-token-balance.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { useNetwork } from './use-network';
1212
import { useTokenMetainfo } from './use-token-metainfo';
1313
import { useWallet } from './use-wallet';
1414

15+
const REFETCH_INTERVAL = 3_000;
16+
1517
export const useTokenBalance = (): {
1618
mainTokenBalance: Amount | null;
1719
currentBalances: TokenBalanceType[];
@@ -63,7 +65,7 @@ export const useTokenBalance = (): {
6365
);
6466
},
6567
{
66-
refetchInterval: 5000,
68+
refetchInterval: REFETCH_INTERVAL,
6769
keepPreviousData: true,
6870
enabled: availableBalanceFetching,
6971
},
@@ -93,7 +95,7 @@ export const useTokenBalance = (): {
9395
);
9496
},
9597
{
96-
refetchInterval: 5000,
98+
refetchInterval: REFETCH_INTERVAL,
9799
enabled: availableBalanceFetching,
98100
},
99101
);

packages/adena-extension/src/hooks/wallet/transaction-gas/use-get-estimate-gas-info.ts

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { DEFAULT_GAS_USED } from '@common/constants/gas.constant';
21
import { GasToken } from '@common/constants/token.constant';
2+
import { DEFAULT_GAS_WANTED } from '@common/constants/tx.constant';
33
import { Tx } from '@gnolang/tm2-js-client';
44
import { useAdenaContext, useWalletContext } from '@hooks/use-context';
55
import { TransactionService } from '@services/index';
@@ -55,7 +55,7 @@ export const useGetDefaultEstimateGasInfo = (
5555
document: Document | null | undefined,
5656
options?: UseQueryOptions<GasInfo | null, Error>,
5757
): UseQueryResult<GasInfo | null> => {
58-
return useGetEstimateGasInfo(document, DEFAULT_GAS_USED, options);
58+
return useGetEstimateGasInfo(document, DEFAULT_GAS_WANTED, options);
5959
};
6060

6161
export const makeEstimateGasTransaction = async (
@@ -64,6 +64,7 @@ export const makeEstimateGasTransaction = async (
6464
document: Document | null | undefined,
6565
gasUsed: number,
6666
gasPrice: number | null,
67+
withSignTransaction = false,
6768
): Promise<Tx | null> => {
6869
if (!document || !gasPrice) {
6970
return null;
@@ -76,10 +77,9 @@ export const makeEstimateGasTransaction = async (
7677

7778
const modifiedDocument = modifyDocument(document, gasWanted, gasFee);
7879

79-
// current tx size not calculate
80-
// if (isInitializedAccount) {
81-
// return documentToDefaultTx(modifiedDocument);
82-
// }
80+
if (!withSignTransaction) {
81+
return documentToDefaultTx(modifiedDocument);
82+
}
8383

8484
const { signed } = await transactionService
8585
.createTransaction(wallet, modifiedDocument)
@@ -109,7 +109,14 @@ export const useGetEstimateGasInfo = (
109109
return null;
110110
}
111111

112-
return makeEstimateGasTransaction(wallet, transactionService, document, gasUsed, gasPrice);
112+
return makeEstimateGasTransaction(
113+
wallet,
114+
transactionService,
115+
document,
116+
gasUsed,
117+
gasPrice,
118+
true,
119+
);
113120
}
114121

115122
return useQuery<GasInfo | null, Error>({
@@ -137,16 +144,7 @@ export const useGetEstimateGasInfo = (
137144
gasUsed,
138145
errorMessage: null,
139146
}))
140-
.catch((e: Error) => {
141-
if (e?.message === '/std.InvalidPubKeyError') {
142-
return {
143-
gasUsed: DEFAULT_GAS_USED,
144-
errorMessage: null,
145-
};
146-
}
147-
148-
return null;
149-
});
147+
.catch(() => null);
150148

151149
if (!resultGasUsed) {
152150
return {

packages/adena-extension/src/hooks/wallet/transaction-gas/use-get-estimate-gas-price-tiers.ts

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,30 @@
1-
import { DEFAULT_GAS_PRICE_RATE, DEFAULT_GAS_USED } from '@common/constants/gas.constant';
2-
import { INVALID_PUBLIC_KEY_ERROR_TYPE } from '@common/constants/tx-error.constant';
1+
import { DEFAULT_GAS_PRICE_RATE } from '@common/constants/gas.constant';
2+
import { DEFAULT_GAS_WANTED } from '@common/constants/tx.constant';
33
import { useAdenaContext, useWalletContext } from '@hooks/use-context';
4+
import { useCurrentAccount } from '@hooks/use-current-account';
45
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
56
import { NetworkFeeSettingInfo, NetworkFeeSettingType } from '@types';
67
import { Document } from 'adena-module';
78
import BigNumber from 'bignumber.js';
9+
import { useIsInitializedAccount } from '../use-get-account-info';
810
import { makeEstimateGasTransaction } from './use-get-estimate-gas-info';
911
import { useGetGasPrice } from './use-get-gas-price';
1012

11-
export const GET_ESTIMATE_GAS_PRICE_TIERS = 'transactionGas/getEstimateGasPriceTiers';
12-
1313
const REFETCH_INTERVAL = 5_000;
1414

15+
export const GET_ESTIMATE_GAS_PRICE_TIERS = 'transactionGas/getEstimateGasPriceTiers';
16+
1517
export const useGetEstimateGasPriceTiers = (
1618
document: Document | null | undefined,
1719
gasUsed: number | undefined,
1820
gasAdjustment: string,
1921
options?: UseQueryOptions<NetworkFeeSettingInfo[] | null, Error>,
2022
): UseQueryResult<NetworkFeeSettingInfo[] | null> => {
23+
const { currentAddress } = useCurrentAccount();
2124
const { transactionGasService, transactionService } = useAdenaContext();
2225
const { data: gasPrice } = useGetGasPrice();
2326
const { wallet } = useWalletContext();
27+
const isInitializedAccount = useIsInitializedAccount(currentAddress);
2428

2529
return useQuery<NetworkFeeSettingInfo[] | null, Error>({
2630
queryKey: [
@@ -31,22 +35,28 @@ export const useGetEstimateGasPriceTiers = (
3135
gasUsed,
3236
gasAdjustment,
3337
gasPrice || 0,
38+
isInitializedAccount,
3439
],
3540
queryFn: async (): Promise<NetworkFeeSettingInfo[] | null> => {
36-
if (!transactionService || !transactionGasService || !document || !gasPrice) {
41+
if (
42+
!transactionService ||
43+
!transactionGasService ||
44+
!document ||
45+
!gasPrice ||
46+
isInitializedAccount === null
47+
) {
3748
return null;
3849
}
3950

4051
return Promise.all(
4152
Object.keys(NetworkFeeSettingType).map(async (key) => {
4253
const tier = key as NetworkFeeSettingType;
4354

44-
const adjustGasUsedBN = BigNumber(gasUsed || DEFAULT_GAS_USED).multipliedBy(
45-
DEFAULT_GAS_PRICE_RATE[tier],
46-
);
55+
const adjustGasUsedBN = BigNumber(gasUsed || DEFAULT_GAS_WANTED)
56+
.multipliedBy(DEFAULT_GAS_PRICE_RATE[tier])
57+
.multipliedBy(gasAdjustment);
4758
const adjustGasUsed = adjustGasUsedBN.toFixed(0, BigNumber.ROUND_DOWN);
48-
const adjustedGasPriceBN = BigNumber(gasPrice).multipliedBy(gasAdjustment);
49-
const adjustedGasPrice = adjustedGasPriceBN.toNumber();
59+
const adjustedGasPriceBN = BigNumber(gasPrice);
5060
const gasFee = adjustedGasPriceBN
5161
.multipliedBy(adjustGasUsed)
5262
.toFixed(0, BigNumber.ROUND_UP);
@@ -57,22 +67,17 @@ export const useGetEstimateGasPriceTiers = (
5767
document,
5868
Number(adjustGasUsed),
5969
adjustedGasPriceBN.toNumber(),
70+
!isInitializedAccount,
6071
);
6172

62-
console.log('tx', tx);
63-
console.log('gasUsed', gasUsed);
64-
console.log('gasPrice', adjustedGasPrice);
65-
console.log('gasFee', gasFee);
66-
console.log('document', document);
67-
6873
if (!tx) {
6974
return {
7075
settingType: tier,
7176
gasInfo: {
7277
gasFee: 0,
7378
gasUsed: Number(adjustGasUsed),
7479
gasWanted: Number(adjustGasUsed),
75-
gasPrice: adjustedGasPrice,
80+
gasPrice: gasPrice,
7681
hasError: true,
7782
simulateErrorMessage: 'Failed to simulate transaction',
7883
},
@@ -82,32 +87,46 @@ export const useGetEstimateGasPriceTiers = (
8287
const result = await transactionGasService
8388
.simulateTx(tx)
8489
.then((simulateResult) => {
85-
return {
86-
gasUsed: simulateResult.gasUsed.toNumber(),
87-
errorMessage: null,
88-
};
89-
})
90-
.catch((e: Error) => {
91-
if (e?.message === INVALID_PUBLIC_KEY_ERROR_TYPE) {
90+
if (simulateResult.gasUsed.toNumber() > Number(adjustGasUsed)) {
9291
return {
93-
gasUsed: Number(adjustGasUsed),
94-
errorMessage: null,
92+
gasUsed: 0,
93+
errorMessage: 'Network fee too low',
9594
};
9695
}
9796

9897
return {
9998
gasUsed: Number(adjustGasUsed),
99+
errorMessage: null,
100+
};
101+
})
102+
.catch((e: Error) => {
103+
return {
104+
gasUsed: 0,
100105
errorMessage: e?.message || '',
101106
};
102107
});
103108

109+
if (result.gasUsed === 0) {
110+
return {
111+
settingType: tier,
112+
gasInfo: {
113+
gasFee: 0,
114+
gasUsed: Number(adjustGasUsed),
115+
gasWanted: Number(adjustGasUsed),
116+
gasPrice: gasPrice,
117+
hasError: true,
118+
simulateErrorMessage: result.errorMessage,
119+
},
120+
};
121+
}
122+
104123
return {
105124
settingType: tier,
106125
gasInfo: {
107126
gasFee: Number(gasFee),
108-
gasUsed: result.gasUsed,
109-
gasWanted: result.gasUsed,
110-
gasPrice: adjustedGasPrice,
127+
gasUsed: Number(adjustGasUsed),
128+
gasWanted: Number(adjustGasUsed),
129+
gasPrice: gasPrice,
111130
hasError: result.errorMessage !== null,
112131
simulateErrorMessage: result.errorMessage,
113132
},

packages/adena-extension/src/hooks/wallet/transaction-history/use-transaction-history-page.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useNetwork } from '@hooks/use-network';
88
import { useTokenMetainfo } from '@hooks/use-token-metainfo';
99
import { TransactionInfo, TransactionWithPageInfo } from '@types';
1010

11-
const REFETCH_INTERVAL = 5_000;
11+
const REFETCH_INTERVAL = 3_000;
1212

1313
export const useTransactionHistoryPage = ({
1414
enabled,

packages/adena-extension/src/hooks/wallet/use-get-account-info.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AccountInfo } from '@common/provider/gno';
22
import { useAdenaContext } from '@hooks/use-context';
3+
import { useNetwork } from '@hooks/use-network';
34
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
45
import { useMemo } from 'react';
56

@@ -10,9 +11,10 @@ export const useGetAccountInfo = (
1011
options?: UseQueryOptions<AccountInfo | null, Error>,
1112
): UseQueryResult<AccountInfo | null> => {
1213
const { accountService } = useAdenaContext();
14+
const { currentNetwork } = useNetwork();
1315

1416
return useQuery<AccountInfo | null, Error>({
15-
queryKey: [GET_ACCOUNT_INFO, accountService, address || ''],
17+
queryKey: [GET_ACCOUNT_INFO, accountService, address || '', currentNetwork?.chainId],
1618
queryFn: async (): Promise<AccountInfo | null> => {
1719
if (!accountService || !address) {
1820
return null;
@@ -29,10 +31,14 @@ export const useGetAccountInfo = (
2931
export const useIsInitializedAccount = (
3032
address: string | null | undefined,
3133
options?: UseQueryOptions<AccountInfo | null, Error>,
32-
): boolean => {
34+
): boolean | null => {
3335
const result = useGetAccountInfo(address, options);
3436

3537
return useMemo(() => {
38+
if (!address || !result.data) {
39+
return null;
40+
}
41+
3642
return result.data?.status === 'ACTIVE' && result.data.publicKey !== null;
37-
}, [result.data]);
43+
}, [address, result.data, result.isLoading]);
3844
};

packages/adena-extension/src/pages/popup/wallet/account-details/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ const AccountDetailsContainer: React.FC = () => {
6363
const moveGnoscan = useCallback(() => {
6464
const scannerUrl = currentNetwork.linkUrl || SCANNER_URL;
6565
const openLinkUrl = scannerParameters
66-
? `${scannerUrl}/accounts/${address}?${makeQueryString(scannerParameters)}`
67-
: `${scannerUrl}/accounts/${address}`;
66+
? `${scannerUrl}/account/${address}?${makeQueryString(scannerParameters)}`
67+
: `${scannerUrl}/account/${address}`;
6868
openLink(openLinkUrl);
6969
}, [address]);
7070

packages/adena-extension/src/pages/popup/wallet/account-initialization/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { CommonFullContentLayout } from '@components/atoms';
22
import AccountInitializationPage from '@components/pages/account-initialization/account-initialization';
3-
import { useAdenaContext, useWalletContext } from '@hooks/use-context';
3+
import { useWalletContext } from '@hooks/use-context';
44
import { useCurrentAccount } from '@hooks/use-current-account';
55

6+
/**
7+
* The page to initialize your account is deprecated for now.
8+
* Keep it for account initialization.
9+
*/
610
export default function AccountInitialization(): JSX.Element {
711
const { wallet } = useWalletContext();
812
const { currentAccount, currentAddress } = useCurrentAccount();
9-
const { transactionService } = useAdenaContext();
1013

1114
const moveBack = (): void => {
1215
history.back();
@@ -17,7 +20,8 @@ export default function AccountInitialization(): JSX.Element {
1720
return false;
1821
}
1922

20-
return transactionService.broadcastEmptyTransaction(wallet, currentAccount);
23+
// Change it to run an empty transaction that can be initialized.
24+
return true;
2125
};
2226

2327
return (

0 commit comments

Comments
 (0)