Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Tx } from '@gnolang/tm2-js-client';
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
import { Account, Document, documentToDefaultTx, Wallet } from 'adena-module';
import BigNumber from 'bignumber.js';

import { MINIMUM_GAS_PRICE } from '@common/constants/gas.constant';
import { GasToken } from '@common/constants/token.constant';
import { DEFAULT_GAS_WANTED } from '@common/constants/tx.constant';
import { Tx } from '@gnolang/tm2-js-client';
import { useAdenaContext, useWalletContext } from '@hooks/use-context';
import { useCurrentAccount } from '@hooks/use-current-account';
import { TransactionService } from '@services/index';
import { useQuery, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
import { GasInfo } from '@types';
import { Document, documentToDefaultTx, Wallet } from 'adena-module';
import BigNumber from 'bignumber.js';

import { useGetGasPrice } from './use-get-gas-price';

export const GET_ESTIMATE_GAS_INFO_KEY = 'transactionGas/useGetSingleEstimateGas';
Expand Down Expand Up @@ -54,6 +57,7 @@ export const useGetDefaultEstimateGasInfo = (

export const makeEstimateGasTransaction = async (
wallet: Wallet | null,
account: Account | null,
transactionService: TransactionService | null,
document: Document | null | undefined,
gasUsed: number,
Expand All @@ -65,7 +69,7 @@ export const makeEstimateGasTransaction = async (
}

const { gasFee, gasWanted } = makeGasInfoBy(gasUsed, gasPrice);
if (!transactionService || !gasFee || !gasWanted || !wallet) {
if (!transactionService || !gasFee || !gasWanted || !wallet || !account) {
return null;
}

Expand All @@ -75,7 +79,7 @@ export const makeEstimateGasTransaction = async (
}

const { signed } = await transactionService
.createTransaction(wallet, modifiedDocument)
.createTransaction(wallet, account, modifiedDocument)
.catch(() => {
return {
signed: null,
Expand All @@ -93,6 +97,7 @@ export const useGetEstimateGasInfo = (
gasUsed: number,
options?: UseQueryOptions<GasInfo | null, Error>,
): UseQueryResult<GasInfo | null> => {
const { currentAccount, currentAddress } = useCurrentAccount();
const { data: gasPrice } = useGetGasPrice();
const { wallet } = useWalletContext();
const { transactionService, transactionGasService } = useAdenaContext();
Expand All @@ -104,6 +109,7 @@ export const useGetEstimateGasInfo = (

return makeEstimateGasTransaction(
wallet,
currentAccount,
transactionService,
document,
gasUsed,
Expand All @@ -114,10 +120,14 @@ export const useGetEstimateGasInfo = (

return useQuery<GasInfo | null, Error>({
queryKey: [
currentAccount?.id,
currentAddress,
GET_ESTIMATE_GAS_INFO_KEY,
transactionGasService,
document?.msgs || '',
document?.memo || '',
document?.account_number,
document?.sequence,
gasUsed,
gasPrice || 0,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ export const useGetEstimateGasPriceTiers = (
gasAdjustment: string,
options?: UseQueryOptions<NetworkFeeSettingInfo[] | null, Error>,
): UseQueryResult<NetworkFeeSettingInfo[] | null> => {
const { currentAddress } = useCurrentAccount();
const { currentAccount, currentAddress } = useCurrentAccount();
const { transactionGasService, transactionService } = useAdenaContext();
const { data: gasPrice } = useGetGasPrice();
const { wallet } = useWalletContext();
const isInitializedAccount = useIsInitializedAccount(currentAddress);

return useQuery<NetworkFeeSettingInfo[] | null, Error>({
queryKey: [
wallet,
currentAccount?.id,
GET_ESTIMATE_GAS_PRICE_TIERS,
transactionGasService,
document?.msgs,
document?.memo,
document?.account_number,
document?.sequence,
gasUsed,
gasAdjustment,
gasPrice || 0,
Expand Down Expand Up @@ -71,6 +75,7 @@ export const useGetEstimateGasPriceTiers = (

const tx = await makeEstimateGasTransaction(
wallet,
currentAccount,
transactionService,
document,
Number(adjustGasUsed),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ const ApproveSignTransactionContainer: React.FC = () => {

try {
setProcessType('PROCESSING');
const { signed } = await transactionService.createTransaction(wallet, document);
const { signed } = await transactionService.createTransaction(
wallet,
currentAccount,
document,
);
const encodedTransaction = transactionService.encodeTransaction(signed);
setResponse(
InjectionMessageInstance.success(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ const ApproveTransactionContainer: React.FC = () => {
const walletInstance = wallet.clone();
walletInstance.currentAccountId = currentAccount.id;

const { signed } = await transactionService.createTransaction(walletInstance, document);
const { signed } = await transactionService.createTransaction(
walletInstance,
currentAccount,
document,
);

const hash = transactionService.createHash(signed);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ const NFTTransferSummaryContainer: React.FC = () => {
const walletInstance = wallet.clone();
walletInstance.currentAccountId = currentAccount.id;

const { signed } = await transactionService.createTransaction(walletInstance, document);
const { signed } = await transactionService.createTransaction(
walletInstance,
currentAccount,
document,
);

return transactionService.sendTransaction(walletInstance, currentAccount, signed).catch((e) => {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ const TransferSummaryContainer: React.FC = () => {
const walletInstance = wallet.clone();
walletInstance.currentAccountId = currentAccount.id;

const { signed } = await transactionService.createTransaction(walletInstance, document);
const { signed } = await transactionService.createTransaction(
walletInstance,
currentAccount,
document,
);

return transactionService.sendTransaction(walletInstance, currentAccount, signed).catch((e) => {
console.error(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ export class TransactionService {
*/
public createTransaction = async (
wallet: Wallet,
account: Account,
document: Document,
): Promise<{ signed: Tx; signature: EncodeTxSignature[] }> => {
const provider = this.getGnoProvider();
const { signed, signature } = await wallet.sign(provider, document);
const { signed, signature } = await wallet.signByAccountId(provider, account.id, document);
const encodedSignature = signature.map((s) => ({
pubKey: {
typeUrl: s?.pub_key?.type_url,
Expand Down