Skip to content

Commit d87b9b7

Browse files
committed
fix: update account state
1 parent f41711a commit d87b9b7

File tree

7 files changed

+44
-12
lines changed

7 files changed

+44
-12
lines changed

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1+
import { Tx } from '@gnolang/tm2-js-client';
2+
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
3+
import { Account, Document, documentToDefaultTx, Wallet } from 'adena-module';
4+
import BigNumber from 'bignumber.js';
5+
16
import { MINIMUM_GAS_PRICE } from '@common/constants/gas.constant';
27
import { GasToken } from '@common/constants/token.constant';
38
import { DEFAULT_GAS_WANTED } from '@common/constants/tx.constant';
4-
import { Tx } from '@gnolang/tm2-js-client';
59
import { useAdenaContext, useWalletContext } from '@hooks/use-context';
10+
import { useCurrentAccount } from '@hooks/use-current-account';
611
import { TransactionService } from '@services/index';
7-
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
812
import { GasInfo } from '@types';
9-
import { Document, documentToDefaultTx, Wallet } from 'adena-module';
10-
import BigNumber from 'bignumber.js';
13+
1114
import { useGetGasPrice } from './use-get-gas-price';
1215

1316
export const GET_ESTIMATE_GAS_INFO_KEY = 'transactionGas/useGetSingleEstimateGas';
@@ -54,6 +57,7 @@ export const useGetDefaultEstimateGasInfo = (
5457

5558
export const makeEstimateGasTransaction = async (
5659
wallet: Wallet | null,
60+
account: Account | null,
5761
transactionService: TransactionService | null,
5862
document: Document | null | undefined,
5963
gasUsed: number,
@@ -65,7 +69,7 @@ export const makeEstimateGasTransaction = async (
6569
}
6670

6771
const { gasFee, gasWanted } = makeGasInfoBy(gasUsed, gasPrice);
68-
if (!transactionService || !gasFee || !gasWanted || !wallet) {
72+
if (!transactionService || !gasFee || !gasWanted || !wallet || !account) {
6973
return null;
7074
}
7175

@@ -75,7 +79,7 @@ export const makeEstimateGasTransaction = async (
7579
}
7680

7781
const { signed } = await transactionService
78-
.createTransaction(wallet, modifiedDocument)
82+
.createTransaction(wallet, account, modifiedDocument)
7983
.catch(() => {
8084
return {
8185
signed: null,
@@ -93,6 +97,7 @@ export const useGetEstimateGasInfo = (
9397
gasUsed: number,
9498
options?: UseQueryOptions<GasInfo | null, Error>,
9599
): UseQueryResult<GasInfo | null> => {
100+
const { currentAccount, currentAddress } = useCurrentAccount();
96101
const { data: gasPrice } = useGetGasPrice();
97102
const { wallet } = useWalletContext();
98103
const { transactionService, transactionGasService } = useAdenaContext();
@@ -104,6 +109,7 @@ export const useGetEstimateGasInfo = (
104109

105110
return makeEstimateGasTransaction(
106111
wallet,
112+
currentAccount,
107113
transactionService,
108114
document,
109115
gasUsed,
@@ -114,10 +120,14 @@ export const useGetEstimateGasInfo = (
114120

115121
return useQuery<GasInfo | null, Error>({
116122
queryKey: [
123+
currentAccount?.id,
124+
currentAddress,
117125
GET_ESTIMATE_GAS_INFO_KEY,
118126
transactionGasService,
119127
document?.msgs || '',
120128
document?.memo || '',
129+
document?.account_number,
130+
document?.sequence,
121131
gasUsed,
122132
gasPrice || 0,
123133
],

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,22 @@ export const useGetEstimateGasPriceTiers = (
2828
gasAdjustment: string,
2929
options?: UseQueryOptions<NetworkFeeSettingInfo[] | null, Error>,
3030
): UseQueryResult<NetworkFeeSettingInfo[] | null> => {
31-
const { currentAddress } = useCurrentAccount();
31+
const { currentAccount, currentAddress } = useCurrentAccount();
3232
const { transactionGasService, transactionService } = useAdenaContext();
3333
const { data: gasPrice } = useGetGasPrice();
3434
const { wallet } = useWalletContext();
3535
const isInitializedAccount = useIsInitializedAccount(currentAddress);
3636

3737
return useQuery<NetworkFeeSettingInfo[] | null, Error>({
3838
queryKey: [
39+
wallet,
40+
currentAccount?.id,
3941
GET_ESTIMATE_GAS_PRICE_TIERS,
4042
transactionGasService,
4143
document?.msgs,
4244
document?.memo,
45+
document?.account_number,
46+
document?.sequence,
4347
gasUsed,
4448
gasAdjustment,
4549
gasPrice || 0,
@@ -71,6 +75,7 @@ export const useGetEstimateGasPriceTiers = (
7175

7276
const tx = await makeEstimateGasTransaction(
7377
wallet,
78+
currentAccount,
7479
transactionService,
7580
document,
7681
Number(adjustGasUsed),

packages/adena-extension/src/pages/popup/wallet/approve-sign-transaction/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,11 @@ const ApproveSignTransactionContainer: React.FC = () => {
282282

283283
try {
284284
setProcessType('PROCESSING');
285-
const { signed } = await transactionService.createTransaction(wallet, document);
285+
const { signed } = await transactionService.createTransaction(
286+
wallet,
287+
currentAccount,
288+
document,
289+
);
286290
const encodedTransaction = transactionService.encodeTransaction(signed);
287291
setResponse(
288292
InjectionMessageInstance.success(

packages/adena-extension/src/pages/popup/wallet/approve-transaction-main/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ const ApproveTransactionContainer: React.FC = () => {
351351
const walletInstance = wallet.clone();
352352
walletInstance.currentAccountId = currentAccount.id;
353353

354-
const { signed } = await transactionService.createTransaction(walletInstance, document);
354+
const { signed } = await transactionService.createTransaction(
355+
walletInstance,
356+
currentAccount,
357+
document,
358+
);
355359

356360
const hash = transactionService.createHash(signed);
357361

packages/adena-extension/src/pages/popup/wallet/nft-transfer-summary/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ const NFTTransferSummaryContainer: React.FC = () => {
126126
const walletInstance = wallet.clone();
127127
walletInstance.currentAccountId = currentAccount.id;
128128

129-
const { signed } = await transactionService.createTransaction(walletInstance, document);
129+
const { signed } = await transactionService.createTransaction(
130+
walletInstance,
131+
currentAccount,
132+
document,
133+
);
130134

131135
return transactionService.sendTransaction(walletInstance, currentAccount, signed).catch((e) => {
132136
console.error(e);

packages/adena-extension/src/pages/popup/wallet/transfer-summary/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ const TransferSummaryContainer: React.FC = () => {
192192
const walletInstance = wallet.clone();
193193
walletInstance.currentAccountId = currentAccount.id;
194194

195-
const { signed } = await transactionService.createTransaction(walletInstance, document);
195+
const { signed } = await transactionService.createTransaction(
196+
walletInstance,
197+
currentAccount,
198+
document,
199+
);
196200

197201
return transactionService.sendTransaction(walletInstance, currentAccount, signed).catch((e) => {
198202
console.error(e);

packages/adena-extension/src/services/transaction/transaction.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ export class TransactionService {
125125
*/
126126
public createTransaction = async (
127127
wallet: Wallet,
128+
account: Account,
128129
document: Document,
129130
): Promise<{ signed: Tx; signature: EncodeTxSignature[] }> => {
130131
const provider = this.getGnoProvider();
131-
const { signed, signature } = await wallet.sign(provider, document);
132+
const { signed, signature } = await wallet.signByAccountId(provider, account.id, document);
132133
const encodedSignature = signature.map((s) => ({
133134
pubKey: {
134135
typeUrl: s?.pub_key?.type_url,

0 commit comments

Comments
 (0)