Skip to content

Commit af90607

Browse files
committed
chore: fixing decimal effect dep
1 parent 8c2f0f4 commit af90607

File tree

11 files changed

+60
-48
lines changed

11 files changed

+60
-48
lines changed

src/features/gateway/GatewayFlow.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { paths } from "../../pages/routes";
55
import { usePageTitle } from "../../providers/TitleProviders";
66
import { TransactionTypeTabs } from "../transactions/components/TransactionTypeTabs";
77
import { GatewayInitialStep } from "./steps/GatewayInitialStep";
8-
import { GatewayFeesStep } from "./steps/GatwayFeesStep";
8+
import { GatewayFeesStep } from "./steps/GatewayFeesStep";
99

1010
export enum GatewayConfigurationStep {
1111
INITIAL = "initial",

src/features/gateway/gatewayHooks.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export const useGatewayFees = (
133133
}, [gateway]);
134134

135135
useEffect(() => {
136+
console.log(`gateway amounts effect`, gateway, amount);
136137
setAmountsPending(true);
137138
if (!gateway || !decimals) {
138139
return;
@@ -142,13 +143,13 @@ export const useGatewayFees = (
142143
.estimateOutput(new BigNumber(amount).shiftedBy(decimals))
143144
.shiftedBy(-decimals);
144145
setOutputAmount(estimatedOutputBn.toFixed());
145-
console.log(`gateway estimated output: ${estimatedOutputBn}`);
146+
console.log(`gateway amount estimated output: ${estimatedOutputBn}`);
146147

147148
const minimumAmountBn = gateway.fees.minimumAmount.shiftedBy(-decimals);
148149
setMinimumAmount(minimumAmountBn.toFixed());
149-
console.log(`gateway minimum amount: ${estimatedOutputBn}`);
150+
console.log(`gateway amount minimum: ${estimatedOutputBn}`);
150151
setAmountsPending(false);
151-
}, [gateway, amount]);
152+
}, [gateway, decimals, amount]);
152153

153154
return {
154155
decimals,

src/features/gateway/steps/GatwayFeesStep.tsx src/features/gateway/steps/GatewayFeesStep.tsx

+17-9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
getRenAssetName,
3737
} from "../../../utils/tokensConfig";
3838
import { $exchangeRates, $marketData } from "../../marketData/marketDataSlice";
39+
import { findAssetExchangeRate } from "../../marketData/marketDataUtils";
3940
import { useChains } from "../../network/networkHooks";
4041
import { $network } from "../../network/networkSlice";
4142
import { useWallet } from "../../wallet/walletHooks";
@@ -80,8 +81,13 @@ export const GatewayFeesStep: FunctionComponent<GatewayStepProps> = ({
8081
minimumAmount,
8182
amountsPending,
8283
} = fees;
84+
8385
const rates = useSelector($exchangeRates);
84-
const outputAmountUsd = Number(outputAmount) * 69.42; // TODO
86+
const outputAmountUsdRate = findAssetExchangeRate(rates, asset);
87+
const outputAmountUsd =
88+
outputAmountUsdRate !== null
89+
? Number(outputAmount) * outputAmountUsdRate
90+
: null;
8591

8692
const Header = (
8793
<PaperHeader>
@@ -150,13 +156,15 @@ export const GatewayFeesStep: FunctionComponent<GatewayStepProps> = ({
150156
/>
151157
}
152158
valueEquivalent={
153-
<NumberFormatText
154-
prefix=" = $"
155-
value={outputAmountUsd}
156-
spacedSuffix="USD"
157-
decimalScale={2}
158-
fixedDecimalScale
159-
/>
159+
outputAmountUsd !== null ? (
160+
<NumberFormatText
161+
prefix=" = $"
162+
value={outputAmountUsd}
163+
spacedSuffix="USD"
164+
decimalScale={2}
165+
fixedDecimalScale
166+
/>
167+
) : null
160168
}
161169
Icon={<Icon fontSize="inherit" />}
162170
/>
@@ -166,7 +174,7 @@ export const GatewayFeesStep: FunctionComponent<GatewayStepProps> = ({
166174
<PaperContent topPadding bottomPadding>
167175
<span>Feessss</span>
168176
</PaperContent>
169-
<Debug it={{ fees, transactions }} />
177+
<Debug it={{ fees }} />
170178
</>
171179
);
172180
};

src/features/marketData/marketDataHooks.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import {
1515
CoingeckoReferenceData,
1616
coingeckoSymbols,
1717
fetchMarketDataGasPrices,
18-
mapBandchainToExchangeData,
19-
mapCoingeckoToExchangeData,
18+
mapBandchainToExchangeRate,
19+
mapCoingeckoToExchangeRate,
2020
} from "./marketDataUtils";
2121

2222
const dataRefreshInterval = 30; // seconds
@@ -39,7 +39,7 @@ export const useExchangeRates = () => {
3939
fetchBandchainExchangeRates()
4040
.then((data: Array<BandchainReferenceData>) => {
4141
report(SystemType.Bandchain, SystemStatus.Operational);
42-
const rates = mapBandchainToExchangeData(data);
42+
const rates = mapBandchainToExchangeRate(data);
4343
dispatch(setExchangeRates(rates));
4444
})
4545
.catch((error: any) => {

src/features/marketData/marketDataUtils.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export type CoingeckoReferenceData = {
4545
current_price: number;
4646
};
4747

48-
export const mapBandchainToExchangeData = (
48+
export const mapBandchainToExchangeRate = (
4949
referenceData: Array<BandchainReferenceData>
5050
) => {
5151
return referenceData.map((entry: any) => {
@@ -58,7 +58,7 @@ export const mapBandchainToExchangeData = (
5858
});
5959
};
6060

61-
export const mapCoingeckoToExchangeData = (
61+
export const mapCoingeckoToExchangeRate = (
6262
entries: Array<CoingeckoReferenceData>
6363
) => {
6464
return entries.map((entry: any) => ({
@@ -77,16 +77,16 @@ export type GasPrice = {
7777
standard: number;
7878
};
7979

80-
export const findExchangeRate = (
80+
export const findAssetExchangeRate = (
8181
exchangeRates: Array<ExchangeRate>,
8282
base: Asset,
8383
quote = USD_SYMBOL
8484
) => {
85-
const symbol = assetsConfig[base].rateSymbol || base;
85+
const rateSymbol = assetsConfig[base].rateSymbol || base;
8686
const rateEntry = exchangeRates.find(
87-
(entry) => entry.pair === getPair(symbol, quote)
87+
(entry) => entry.pair === getPair(rateSymbol, quote)
8888
);
89-
return rateEntry?.rate;
89+
return rateEntry?.rate || null;
9090
};
9191

9292
export type AnyBlockGasPrices = {

src/features/mint-old/steps/MintFeesStep.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import {
5454
import { useFetchFees } from "../../fees/feesHooks";
5555
import { getTransactionFees } from "../../fees/feesUtils";
5656
import { $exchangeRates } from "../../marketData/marketDataSlice";
57-
import { findExchangeRate } from "../../marketData/marketDataUtils";
57+
import { findAssetExchangeRate } from "../../marketData/marketDataUtils";
5858
import { $renNetwork } from "../../network/networkSlice";
5959
import { TransactionFees } from "../../transactions/components/TransactionFees";
6060
import { setCurrentTxId } from "../../transactions/transactionsSlice";
@@ -88,7 +88,7 @@ export const MintFeesStep: FunctionComponent<TxConfigurationStepProps> = ({
8888
const { chain } = useSelector($wallet);
8989
const network = useSelector($renNetwork);
9090
const exchangeRates = useSelector($exchangeRates);
91-
const currencyUsdRate = findExchangeRate(exchangeRates, currency);
91+
const currencyUsdRate = findAssetExchangeRate(exchangeRates, currency);
9292
const handleAmountChange = useCallback((event) => {
9393
const newValue = event.target.value.replace(",", ".");
9494
if (!isNaN(newValue)) {

src/features/release-old/releaseSlice.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createSelector, createSlice, PayloadAction } from "@reduxjs/toolkit";
22
import { RootState } from "../../store/rootReducer";
33
import { BridgeCurrency } from "../../utils/assetConfigs";
44
import { $exchangeRates } from "../marketData/marketDataSlice";
5-
import { findExchangeRate } from "../marketData/marketDataUtils";
5+
import { findAssetExchangeRate } from "../marketData/marketDataUtils";
66

77
type ReleaseState = {
88
currency: BridgeCurrency;
@@ -63,7 +63,7 @@ export const $releaseAmount = createSelector(
6363
export const $releaseCurrencyUsdRate = createSelector(
6464
$releaseCurrency,
6565
$exchangeRates,
66-
(currencySymbol, rates) => findExchangeRate(rates, currencySymbol, "USD")
66+
(currencySymbol, rates) => findAssetExchangeRate(rates, currencySymbol, "USD")
6767
);
6868
export const $releaseUsdAmount = createSelector(
6969
$releaseAmount,

src/features/release-old/steps/ReleaseFeesStep.tsx

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ import {
4141
import { useFetchFees } from "../../fees/feesHooks";
4242
import { getTransactionFees } from "../../fees/feesUtils";
4343
import { $exchangeRates } from "../../marketData/marketDataSlice";
44-
import { findExchangeRate, USD_SYMBOL } from "../../marketData/marketDataUtils";
44+
import {
45+
findAssetExchangeRate,
46+
USD_SYMBOL,
47+
} from "../../marketData/marketDataUtils";
4548
import { $renNetwork } from "../../network/networkSlice";
4649
import { TransactionFees } from "../../transactions/components/TransactionFees";
4750
import {
@@ -103,7 +106,7 @@ export const ReleaseFeesStep: FunctionComponent<TxConfigurationStepProps> = ({
103106
});
104107

105108
const chainConfig = getChainConfig(chain);
106-
const destinationCurrencyUsdRate = findExchangeRate(
109+
const destinationCurrencyUsdRate = findAssetExchangeRate(
107110
rates,
108111
destinationCurrency,
109112
USD_SYMBOL

src/features/release-old/steps/ReleaseProcessStep.tsx

+9-16
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { usePageTitle, usePaperTitle } from "../../../providers/TitleProviders";
4242
import { getBurnChainMap } from "../../../services/rentx";
4343
import { getChainConfigByRentxName } from "../../../utils/assetConfigs";
4444
import { $exchangeRates } from "../../marketData/marketDataSlice";
45-
import { findExchangeRate } from "../../marketData/marketDataUtils";
45+
import { findAssetExchangeRate } from "../../marketData/marketDataUtils";
4646
import {
4747
BrowserNotificationButton,
4848
BrowserNotificationsDrawer,
@@ -116,11 +116,8 @@ export const ReleaseProcessStep: FunctionComponent<RouteComponentProps> = ({
116116
}, [history]);
117117
const sourceChain = parsedTx?.sourceChain;
118118

119-
const {
120-
menuOpened,
121-
handleMenuOpen,
122-
handleMenuClose,
123-
} = useTransactionMenuControl();
119+
const { menuOpened, handleMenuOpen, handleMenuClose } =
120+
useTransactionMenuControl();
124121

125122
const {
126123
modalOpened,
@@ -155,13 +152,10 @@ export const ReleaseProcessStep: FunctionComponent<RouteComponentProps> = ({
155152
return await getBurnChainMap(providers);
156153
}, [enabledChains]);
157154

158-
const {
159-
burnCurrencyConfig,
160-
burnChainConfig,
161-
releaseCurrencyConfig,
162-
} = getBurnAndReleaseParams(tx);
155+
const { burnCurrencyConfig, burnChainConfig, releaseCurrencyConfig } =
156+
getBurnAndReleaseParams(tx);
163157
const amount = Number(tx.targetAmount);
164-
const releaseCurrencyUsdRate = findExchangeRate(
158+
const releaseCurrencyUsdRate = findAssetExchangeRate(
165159
rates,
166160
releaseCurrencyConfig.symbol
167161
);
@@ -270,10 +264,9 @@ type ReleaseTransactionStatusProps = {
270264
burnChainMap: any;
271265
};
272266

273-
const ReleaseTransactionStatus: FunctionComponent<ReleaseTransactionStatusProps> = ({
274-
tx,
275-
burnChainMap,
276-
}) => {
267+
const ReleaseTransactionStatus: FunctionComponent<
268+
ReleaseTransactionStatusProps
269+
> = ({ tx, burnChainMap }) => {
277270
const { t } = useTranslation();
278271
const history = useHistory();
279272
const location = useLocation();

src/features/transactions/components/TransactionFees.tsx

+7-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { useFetchFees } from "../../fees/feesHooks";
2323
import { getTransactionFees } from "../../fees/feesUtils";
2424
import { $exchangeRates, $gasPrices } from "../../marketData/marketDataSlice";
2525
import {
26-
findExchangeRate,
26+
findAssetExchangeRate,
2727
findGasPrice,
2828
USD_SYMBOL,
2929
} from "../../marketData/marketDataUtils";
@@ -55,15 +55,19 @@ export const TransactionFees: FunctionComponent<TransactionFeesProps> = ({
5555
const nativeCurrencyConfig = getCurrencyConfig(getNativeCurrency(currency));
5656
const exchangeRates = useSelector($exchangeRates);
5757
const gasPrices = useSelector($gasPrices);
58-
const currencyUsdRate = findExchangeRate(exchangeRates, currency, USD_SYMBOL);
58+
const currencyUsdRate = findAssetExchangeRate(
59+
exchangeRates,
60+
currency,
61+
USD_SYMBOL
62+
);
5963
const gasPrice = findGasPrice(gasPrices, chain);
6064
const targetChainConfig = getChainConfig(chain);
6165
const decimals = getReleaseAssetDecimals(
6266
nativeCurrencyConfig.sourceChain,
6367
nativeCurrencyConfig.symbol
6468
);
6569

66-
const targetChainCurrencyUsdRate = findExchangeRate(
70+
const targetChainCurrencyUsdRate = findAssetExchangeRate(
6771
exchangeRates,
6872
targetChainConfig.nativeCurrency,
6973
USD_SYMBOL

src/features/wallet/walletHooks.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ type WalletData = ReturnType<typeof useMultiwallet> & {
1919
};
2020

2121
const resolveWalletByProvider = (provider: any) => {
22+
if (!provider) {
23+
return Wallet.Metamask; // TODO: is it valid ?
24+
}
2225
if (provider?.isMetaMask) {
2326
return Wallet.Metamask;
2427
}
@@ -34,7 +37,7 @@ const resolveWalletByProvider = (provider: any) => {
3437
if (provider?.isMewConnect || provider?.isMEWConnect) {
3538
return Wallet.MewConnect;
3639
}
37-
console.warn("Unresolved wallet");
40+
console.warn("Unresolved wallet", provider);
3841
return Wallet.Metamask; // throw error?
3942
};
4043

0 commit comments

Comments
 (0)