|
1 | 1 | "use client";
|
2 |
| -import React, { useMemo, useRef } from "react"; |
| 2 | +import React, { useRef } from "react"; |
3 | 3 | import { useEffect, useState } from "react";
|
4 | 4 | import { EncodeObject } from "@cosmjs/proto-signing";
|
5 | 5 | import { SigningStargateClient } from "@cosmjs/stargate";
|
6 | 6 | import { useManager } from "@cosmos-kit/react";
|
7 | 7 | import axios from "axios";
|
8 |
| -import isAfter from "date-fns/isAfter"; |
9 |
| -import parseISO from "date-fns/parseISO"; |
10 | 8 | import { OpenNewWindow } from "iconoir-react";
|
11 | 9 | import Link from "next/link";
|
12 | 10 | import { useRouter } from "next/navigation";
|
13 | 11 | import { event } from "nextjs-google-analytics";
|
14 | 12 | import { SnackbarKey, useSnackbar } from "notistack";
|
15 | 13 |
|
16 | 14 | import { TransactionModal } from "@src/components/layout/TransactionModal";
|
17 |
| -import { SelectOption } from "@src/components/shared/Popup"; |
18 | 15 | import { Snackbar } from "@src/components/shared/Snackbar";
|
19 |
| -import { usePopup } from "@src/context/PopupProvider/PopupProvider"; |
| 16 | +import { useAllowance } from "@src/hooks/useAllowance"; |
20 | 17 | import { useUsdcDenom } from "@src/hooks/useDenom";
|
21 | 18 | import { getSelectedNetwork, useSelectedNetwork } from "@src/hooks/useSelectedNetwork";
|
22 |
| -import { useAllowancesGranted } from "@src/queries/useGrantsQuery"; |
23 | 19 | import { AnalyticsEvents } from "@src/utils/analytics";
|
24 | 20 | import { STATS_APP_URL, uAktDenom } from "@src/utils/constants";
|
25 | 21 | import { customRegistry } from "@src/utils/customRegistry";
|
26 |
| -import { udenomToDenom } from "@src/utils/mathHelpers"; |
27 |
| -import { coinToUDenom } from "@src/utils/priceUtils"; |
28 | 22 | import { UrlService } from "@src/utils/urlUtils";
|
29 | 23 | import { LocalWalletDataType } from "@src/utils/walletUtils";
|
30 | 24 | import { useSelectedChain } from "../CustomChainProvider";
|
@@ -62,32 +56,9 @@ export const WalletProvider = ({ children }) => {
|
62 | 56 | const usdcIbcDenom = useUsdcDenom();
|
63 | 57 | const { disconnect, getOfflineSigner, isWalletConnected, address: walletAddress, connect, username, estimateFee, sign, broadcast } = useSelectedChain();
|
64 | 58 | const { addEndpoints } = useManager();
|
65 |
| - const { data: allowancesGranted } = useAllowancesGranted(walletAddress); |
66 |
| - |
67 |
| - const feeGranters = useMemo(() => { |
68 |
| - if (!walletAddress || !allowancesGranted) { |
69 |
| - return; |
70 |
| - } |
71 |
| - |
72 |
| - const connectedWallet: SelectOption = { text: "Connected Wallet", value: walletAddress }; |
73 |
| - const options: SelectOption[] = allowancesGranted.reduce( |
74 |
| - (acc, grant, index) => { |
75 |
| - if (isAfter(parseISO(grant.allowance.expiration), new Date())) { |
76 |
| - acc.push({ |
77 |
| - text: `${grant.granter} (${udenomToDenom(coinToUDenom(grant.allowance.spend_limit[0]), 6)} AKT)`, |
78 |
| - value: grant.granter, |
79 |
| - selected: index === 0 |
80 |
| - }); |
81 |
| - } |
82 |
| - |
83 |
| - return acc; |
84 |
| - }, |
85 |
| - [connectedWallet] |
86 |
| - ); |
87 |
| - |
88 |
| - return options?.length > 1 ? options : undefined; |
89 |
| - }, [allowancesGranted, walletAddress]); |
90 |
| - const { select } = usePopup(); |
| 59 | + const { |
| 60 | + fee: { default: feeGranter } |
| 61 | + } = useAllowance(); |
91 | 62 |
|
92 | 63 | useEffect(() => {
|
93 | 64 | if (!settings.apiEndpoint || !settings.rpcEndpoint) return;
|
@@ -193,7 +164,6 @@ export const WalletProvider = ({ children }) => {
|
193 | 164 | let pendingSnackbarKey: SnackbarKey | null = null;
|
194 | 165 | try {
|
195 | 166 | const estimatedFees = await estimateFee(msgs);
|
196 |
| - const feeGranter = feeGranters && (await select({ title: "Select fee granter", options: feeGranters })); |
197 | 167 | const txRaw = await sign(msgs, {
|
198 | 168 | ...estimatedFees,
|
199 | 169 | granter: feeGranter
|
|
0 commit comments