Skip to content

Commit

Permalink
fix(HW-613): sushi swap infinity loader on Ethereum mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
iGroza committed Aug 19, 2024
1 parent 3ae0719 commit 6b03541
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/components/swap/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ import {
} from '../ui';
import {WalletRow, WalletRowTypes} from '../wallet-row';

export type PoolsData = Omit<SushiPoolResponse, 'contracts'> & {
contracts: IToken[];
};

export interface SwapProps {
currentWallet: Wallet;
poolData: SushiPoolResponse;
poolData: PoolsData;
estimateData: SushiPoolEstimateResponse | null;
tokenIn: IToken;
tokenOut: IToken;
Expand Down
31 changes: 27 additions & 4 deletions src/screens/SwapStack/swap-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {Alert, Keyboard, View} from 'react-native';
import Toast from 'react-native-toast-message';

import {
PoolsData,
SWAP_SETTINGS_DEFAULT,
Swap,
SwapSettingBottomSheetRef,
Expand Down Expand Up @@ -41,7 +42,6 @@ import {HapticEffects, vibrate} from '@app/services/haptic';
import {
Indexer,
SushiPoolEstimateResponse,
SushiPoolResponse,
SushiRoute,
} from '@app/services/indexer';
import {message} from '@app/services/toast';
Expand Down Expand Up @@ -83,7 +83,7 @@ export const SwapScreen = observer(() => {
const [isSwapInProgress, setSwapInProgress] = useState(false);
const [isApproveInProgress, setApproveInProgress] = useState(false);
const [currentRoute, setCurrentRoute] = useState<SushiRoute | null>(null);
const [poolsData, setPoolsData] = useState<SushiPoolResponse>({
const [poolsData, setPoolsData] = useState<PoolsData>({
contracts: [],
routes: [],
pools: [],
Expand Down Expand Up @@ -490,7 +490,8 @@ export const SwapScreen = observer(() => {
},
});

const [walletAddres, tokenAddress] = value?.id.split('_');
const token = value?.tokens[index];
const [walletAddres, tokenAddress] = token?.tag.split('_');
const wallet = Wallet.getById(AddressUtils.toEth(walletAddres))!;
const generatedISLMContract = {
...Token.generateNativeTokenContract(),
Expand Down Expand Up @@ -1025,6 +1026,7 @@ export const SwapScreen = observer(() => {
Indexer.instance
.sushiPools()
.then(async data => {
logger.log('data', data);
await Token.fetchTokens(true);
const tokens = Array.from(
new Set([
Expand All @@ -1033,6 +1035,27 @@ export const SwapScreen = observer(() => {
]),
)
.map(token => Token.getById(token))
.concat(
data.contracts.map(
contract =>
({
image: contract.icon!,
value: Balance.Empty!,
contract_created_at: contract.created_at!,
created_at: contract.created_at!,
contract_updated_at: contract.updated_at!,
updated_at: contract.updated_at!,
decimals: contract.decimals!,
name: contract.name!,
symbol: contract.symbol!,
id: contract.id!,
is_erc20: true,
is_erc1155: false,
is_erc721: false,
is_in_white_list: true,
}) as IToken,
),
)
.filter(Boolean) as IToken[];

setPoolsData(() => ({
Expand All @@ -1059,7 +1082,7 @@ export const SwapScreen = observer(() => {
AddressUtils.equals(r.token0, RemoteProviderConfig.wethAddress),
) || data.routes[1],
);
if (!data.pools?.length) {
if (!data.pools?.length || !data?.routes?.length) {
showModal(ModalType.error, {
title: getText(I18N.blockRequestErrorTitle),
description: getText(I18N.noSwapRoutesFound),
Expand Down
4 changes: 2 additions & 2 deletions src/services/indexer/indexer.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {HaqqCosmosAddress, IContract, IToken} from '@app/types';
import {HaqqCosmosAddress, IContract} from '@app/types';
import {EIP155_SIGNING_METHODS} from '@app/variables/EIP155';

export type SushiRoute = {
Expand All @@ -18,7 +18,7 @@ export type SushiPool = {
};

export type SushiPoolResponse = {
contracts: IToken[];
contracts: IContract[];
routes: SushiRoute[];
pools: SushiPool[];
};
Expand Down

0 comments on commit 6b03541

Please sign in to comment.