Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync staging to main #294

Merged
merged 4 commits into from
Jun 13, 2024
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
2 changes: 1 addition & 1 deletion initia-registry
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@sentry/nextjs": "^7.99.0",
"@skip-router/core": "4.1.1",
"@skip-router/core": "5.0.2",
"@solana/spl-token": "^0.4.1",
"@solana/wallet-adapter-react": "^0.15.35",
"@solana/wallet-adapter-wallets": "^0.19.31",
Expand Down
10 changes: 7 additions & 3 deletions src/components/SwapWidget/SwapDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,13 @@ export const SwapDetails = ({
{sourceFeeAsset && (
<>
<dt>Estimated Transaction Fee</dt>
<dd>
{gasRequired ?? "-"} {sourceFeeAsset.recommendedSymbol}
</dd>
{sourceChain.chainID !== "stride-1" ? (
<dd>
{gasRequired ?? "-"} {sourceFeeAsset.recommendedSymbol}
</dd>
) : (
<dd>--</dd>
)}
</>
)}
{/* <dt>Gas Amount</dt>
Expand Down
36 changes: 34 additions & 2 deletions src/components/SwapWidget/useSwapWidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function useSwapWidget() {

const skipClient = useSkipClient();

const { assetsByChainID, getFeeAsset, isReady: isAssetsReady } = useAssets();
const { assetsByChainID, getFeeAsset, isReady: isAssetsReady, getAsset } = useAssets();
const { data: chains } = useChains();

const { getWalletRepo } = useCosmosManager();
Expand Down Expand Up @@ -149,7 +149,39 @@ export function useSwapWidget() {
if (srcFeeAsset) {
const parsedFeeBalance = BigNumber(balances[srcFeeAsset.denom] ?? "0").shiftedBy(-(srcFeeAsset.decimals ?? 6));
const parsedGasRequired = BigNumber(gasRequired || "0");
if (srcChain?.chainID === "stride-1") {
const tiaIbcToken = "ibc/BF3B4F53F3694B66E13C23107C84B6485BD2B96296BB7EC680EA77BBA75B4801";
const tiaOnStride = getAsset(tiaIbcToken, "stride-1");
const parsedTiaOnStrideBalance = BigNumber(balances[tiaIbcToken] ?? "0").shiftedBy(
-(tiaOnStride?.decimals ?? 6),
);

const needTia = parsedTiaOnStrideBalance.minus(parsedGasRequired).isLessThanOrEqualTo(0);
const needFeeToken = parsedFeeBalance.minus(parsedGasRequired).isLessThanOrEqualTo(0);
const assetIsFeeDenom = srcFeeAsset.denom === srcAsset.denom;
const assetIsTiaDenom = srcAsset.denom === tiaIbcToken;

if (
parsedGasRequired.gt(0) &&
(assetIsFeeDenom
? parsedAmount.isGreaterThan(parsedBalance.minus(parsedGasRequired)) && needTia
: assetIsTiaDenom
? parsedAmount.isGreaterThan(parsedTiaOnStrideBalance.minus(parsedGasRequired)) && needFeeToken
: needFeeToken
? needTia
: needTia
? needFeeToken
: false)
) {
if (parsedAmount.isGreaterThan(parsedBalance)) {
return `Insufficient balance.`;
}
return `Insufficient balance. You need ≈${gasRequired} ${srcFeeAsset.recommendedSymbol} or ${tiaOnStride?.recommendedSymbol} to accomodate gas fees.`;
}
}

if (
srcChain?.chainID !== "stride-1" &&
parsedGasRequired.gt(0) &&
(srcFeeAsset.denom === srcAsset.denom
? parsedAmount.isGreaterThan(parsedBalance.minus(parsedGasRequired))
Expand All @@ -164,7 +196,7 @@ export function useSwapWidget() {
}

return false;
}, [amountIn, balances, gasRequired, srcAsset, srcFeeAsset]);
}, [amountIn, balances, gasRequired, getAsset, srcAsset, srcChain?.chainID, srcFeeAsset]);

const swapPriceImpactPercent = useMemo(() => {
if (!route?.swapPriceImpactPercent) return undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useChains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function useChains<T = Chain[]>(args: UseChainsQueryArgs<T> = {}) {
const chains = await skipClient.chains({
includeEVM: true,
includeSVM: true,
includeTestnets: process.env.NEXT_PUBLIC_IS_TESTNET ? true : false,
onlyTestnets: process.env.NEXT_PUBLIC_IS_TESTNET ? true : false,
});

return chains
Expand Down
Loading