Skip to content

Commit

Permalink
Add fee market login on claim all component
Browse files Browse the repository at this point in the history
  • Loading branch information
HeesungB authored and Thunnini committed Jul 9, 2024
1 parent d2411c1 commit 9a1f4e7
Showing 1 changed file with 123 additions and 9 deletions.
132 changes: 123 additions & 9 deletions apps/mobile/src/screen/home/components/claim-all/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {CoinPretty, Dec, Int, PricePretty} from '@keplr-wallet/unit';
import {
AminoSignResponse,
BroadcastMode,
FeeCurrency,
StdSignDoc,
} from '@keplr-wallet/types';
import {BACKGROUND_PORT} from '@keplr-wallet/router';
Expand Down Expand Up @@ -222,11 +223,14 @@ export const ClaimAll: FunctionComponent<{isNotReady?: boolean}> = observer(
account.cosmos.makeWithdrawDelegationRewardTx(validatorAddresses);

(async () => {
let feeCurrency = chainInfo.feeCurrencies.find(
cur =>
cur.coinMinimalDenom ===
chainInfo.stakeCurrency?.coinMinimalDenom,
);
// feemarket feature가 있는 경우 이후의 로직에서 사용할 수 있는 fee currency를 찾아야하기 때문에 undefined로 시작시킨다.
let feeCurrency = chainInfo.hasFeature('feemarket')
? undefined
: chainInfo.feeCurrencies.find(
cur =>
cur.coinMinimalDenom ===
chainInfo.stakeCurrency?.coinMinimalDenom,
);

if (chainInfo.hasFeature('osmosis-base-fee-beta') && feeCurrency) {
const queryBaseFee = queriesStore.get(chainInfo.chainId).osmosis
Expand Down Expand Up @@ -293,7 +297,108 @@ export const ClaimAll: FunctionComponent<{isNotReady?: boolean}> = observer(
}
| undefined;

for (const chainFeeCurrency of chainInfo.feeCurrencies) {
const feeCurrencies = await (async () => {
if (chainInfo.hasFeature('feemarket')) {
const queryFeeMarketGasPrices =
queriesStore.get(chainId).cosmos.queryFeeMarketGasPrices;
await queryFeeMarketGasPrices.waitFreshResponse();

const result: FeeCurrency[] = [];

for (const gasPrice of queryFeeMarketGasPrices.gasPrices) {
const currency = await chainInfo.findCurrencyAsync(
gasPrice.denom,
);
if (currency) {
let multiplication = {
low: 1.1,
average: 1.2,
high: 1.3,
};

const multificationConfig =
queriesStore.simpleQuery.queryGet<{
[str: string]:
| {
low: number;
average: number;
high: number;
}
| undefined;
}>(
'https://gjsttg7mkgtqhjpt3mv5aeuszi0zblbb.lambda-url.us-west-2.on.aws',
'/feemarket/info.json',
);

if (multificationConfig.response) {
const _default =
multificationConfig.response.data['__default__'];
if (
_default &&
_default.low != null &&
typeof _default.low === 'number' &&
_default.average != null &&
typeof _default.average === 'number' &&
_default.high != null &&
typeof _default.high === 'number'
) {
multiplication = {
low: _default.low,
average: _default.average,
high: _default.high,
};
}
const specific =
multificationConfig.response.data[
chainInfo.chainIdentifier
];
if (
specific &&
specific.low != null &&
typeof specific.low === 'number' &&
specific.average != null &&
typeof specific.average === 'number' &&
specific.high != null &&
typeof specific.high === 'number'
) {
multiplication = {
low: specific.low,
average: specific.average,
high: specific.high,
};
}
}

result.push({
...currency,
gasPriceStep: {
low: parseFloat(
new Dec(multiplication.low)
.mul(gasPrice.amount)
.toString(),
),
average: parseFloat(
new Dec(multiplication.average)
.mul(gasPrice.amount)
.toString(),
),
high: parseFloat(
new Dec(multiplication.high)
.mul(gasPrice.amount)
.toString(),
),
},
});
}
}

return result;
} else {
return chainInfo.feeCurrencies;
}
})();

for (const chainFeeCurrency of feeCurrencies) {
const currency = await chainInfo.findCurrencyAsync(
chainFeeCurrency.coinMinimalDenom,
);
Expand All @@ -308,23 +413,32 @@ export const ClaimAll: FunctionComponent<{isNotReady?: boolean}> = observer(
);

if (!prev) {
feeCurrency = currency;
feeCurrency = {
...chainFeeCurrency,
...currency,
};
prev = {
balance: balance.balance,
price,
};
} else {
if (!prev.price) {
if (prev.balance.toDec().lt(balance.balance.toDec())) {
feeCurrency = currency;
feeCurrency = {
...chainFeeCurrency,
...currency,
};
prev = {
balance: balance.balance,
price,
};
}
} else if (price) {
if (prev.price.toDec().lt(price.toDec())) {
feeCurrency = currency;
feeCurrency = {
...chainFeeCurrency,
...currency,
};
prev = {
balance: balance.balance,
price,
Expand Down

0 comments on commit 9a1f4e7

Please sign in to comment.