Skip to content

Commit

Permalink
fix: update skip api for unwinding
Browse files Browse the repository at this point in the history
  • Loading branch information
chalabi2 committed Jun 10, 2024
1 parent 5a8d2b1 commit 8408dbb
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 19 deletions.
Binary file modified web-ui/bun.lockb
Binary file not shown.
70 changes: 55 additions & 15 deletions web-ui/components/Assets/modals/rewardsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
Box,
} from '@chakra-ui/react';
import { useChain, useChains } from '@cosmos-kit/react';
import { SkipRouter, SKIP_API_URL } from '@skip-router/core';
import { SkipRouter, SKIP_API_URL, UserAddress } from '@skip-router/core';
import { ibc } from 'interchain-query';
import { useCallback, useState } from 'react';
import { FaInfoCircle } from 'react-icons/fa';
Expand All @@ -42,7 +42,19 @@ import { useSkipExecute } from '@/hooks/useSkipExecute';
import { shiftDigits } from '@/utils';

const RewardsModal = ({ address, isOpen, onClose }: { address: string; isOpen: boolean; onClose: () => void }) => {
const chains = useChains(['cosmoshub', 'osmosis', 'stargaze', 'juno', 'sommelier', 'regen', 'dydx', 'saga']);
const chains = useChains([
'cosmoshub',
'osmosis',
'stargaze',
'juno',
'sommelier',
'regen',
'dydx',
'saga',
'stride',
'noble',
'neutron',
]);

const { wallet } = useChain('quicksilver');

Expand Down Expand Up @@ -81,6 +93,7 @@ const RewardsModal = ({ address, isOpen, onClose }: { address: string; isOpen: b

return balanceData
.map((balanceItem) => {
// filter out native quick tokens
if (balanceItem.denom.startsWith('q') || balanceItem.denom.startsWith('aq') || balanceItem.denom.startsWith('uq')) {
return null;
}
Expand Down Expand Up @@ -133,25 +146,49 @@ const RewardsModal = ({ address, isOpen, onClose }: { address: string; isOpen: b
const { routesData } = useSkipRoutesData(osmosisRoutesDataObjects);

const executeRoute = useSkipExecute(skipClient);

// Helper function to get ordered addresses based on requiredChainAddresses
const getOrderedAddresses = (requiredChainAddresses: string[], allAddresses: UserAddress[]): UserAddress[] => {
return requiredChainAddresses.map((chainID) => {
const addressObj = allAddresses.find((addr) => addr.chainID === chainID);
if (!addressObj) {
throw new Error(`Address for chainID ${chainID} not found`);
}
return addressObj;
});
};

// uses all the data gathered to create the ibc transactions for sending assets to osmosis.
const handleExecuteRoute = async () => {
setIsSigning(true);

const addresses = {
'quicksilver-2': address,
'osmosis-1': chains.osmosis.address,
'cosmoshub-4': chains.cosmoshub.address,
'stargaze-1': chains.stargaze.address,
'sommelier-3': chains.sommelier.address,
'regen-1': chains.regen.address,
'juno-1': chains.juno.address,
'dydx-mainnet-1': chains.dydx.address,
};

// Execute each route in sequence
const allAddresses: UserAddress[] = [
{ chainID: 'quicksilver-2', address },
{ chainID: 'osmosis-1', address: chains.osmosis.address ?? '' },
{ chainID: 'cosmoshub-4', address: chains.cosmoshub.address ?? '' },
{ chainID: 'stargaze-1', address: chains.stargaze.address ?? '' },
{ chainID: 'sommelier-3', address: chains.sommelier.address ?? '' },
{ chainID: 'regen-1', address: chains.regen.address ?? '' },
{ chainID: 'juno-1', address: chains.juno.address ?? '' },
{ chainID: 'dydx-mainnet-1', address: chains.dydx.address ?? '' },
{ chainID: 'stride-1', address: chains.stride.address ?? '' },
{ chainID: 'noble-1', address: chains.noble.address ?? '' },
{ chainID: 'neutron-1', address: chains.neutron.address ?? '' },
];

// Check if any address is undefined
const undefinedAddresses = allAddresses.filter((addr) => !addr.address);
if (undefinedAddresses.length > 0) {
console.error('Some addresses are undefined:', undefinedAddresses);
setIsSigning(false);
return;
}

// Execute each route in sequence with ordered addresses
for (const route of routesData) {
const orderedAddresses = getOrderedAddresses(route?.requiredChainAddresses ?? ([] as string[]), allAddresses);
try {
await executeRoute(route, addresses, refetch);
await executeRoute(route, orderedAddresses, refetch);
} catch (error) {
console.error('Error executing route:', error);
setIsSigning(false);
Expand Down Expand Up @@ -198,6 +235,9 @@ const RewardsModal = ({ address, isOpen, onClose }: { address: string; isOpen: b
'regen-1': 'regen',
'juno-1': 'juno',
'dydx-mainnet-1': 'dydx',
'stride-1': 'stride',
'noble-1': 'noble',
'neutron-1': 'neutron',
};

const getChainName = (chainId: string) => {
Expand Down
2 changes: 1 addition & 1 deletion web-ui/components/Staking/modals/stakingProcessModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export const StakingProcessModal: React.FC<StakingModalProps> = ({ isOpen, onClo
feeAmount = '10000';
} else {
// Default case
const fixedMinGasPrice = fees?.find(({ denom }) => denom === mainDenom)?.average_gas_price ?? '';
const fixedMinGasPrice = fees?.find(({ denom }: { denom: string }) => denom === mainDenom)?.average_gas_price ?? '';
feeAmount = shiftDigits(fixedMinGasPrice, 6).toString();
}

Expand Down
15 changes: 14 additions & 1 deletion web-ui/components/wallet-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@ import {
} from '@/components';

export const WalletButton: React.FC = () => {
const chains = useChains(['quicksilver', 'cosmoshub', 'osmosis', 'stargaze', 'juno', 'sommelier', 'regen', 'umee', 'dydx']);
const chains = useChains([
'quicksilver',
'cosmoshub',
'osmosis',
'stargaze',
'juno',
'sommelier',
'regen',
'umee',
'dydx',
'stride',
'noble',
'neutron',
]);

const { connect, openView, status, message, wallet, isWalletError } = chains.quicksilver;

Expand Down
7 changes: 6 additions & 1 deletion web-ui/hooks/useSkipExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ import { useCallback } from 'react';

import { useToaster, ToastType } from './useToaster';

interface UserAddress {
chainID: string;
address: string;
}

export function useSkipExecute(skipClient: SkipRouter) {
if (!skipClient) {
throw new Error('SkipRouter is not initialized');
}

const toaster = useToaster();

const executeRoute = useCallback(async (route: any, userAddresses: any, refetch: () => void) => {
const executeRoute = useCallback(async (route: any, userAddresses: UserAddress[], refetch: () => void) => {
// Initialize with null and allow for the type to be null or ToastId
let broadcastToastId: ToastId | null = null;

Expand Down
2 changes: 1 addition & 1 deletion web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@interchain-ui/react": "1.10.0",
"@osmonauts/lcd": "^1.0.3",
"@radix-ui/react-icons": "^1.3.0",
"@skip-router/core": "2.4.1",
"@skip-router/core": "5.0.0",
"@tanstack/react-query": "4.36.1",
"@tanstack/react-query-devtools": "4.36.1",
"@types/crypto-js": "^4.2.1",
Expand Down

0 comments on commit 8408dbb

Please sign in to comment.