Skip to content

Commit

Permalink
Merge branch 'master' into id-730
Browse files Browse the repository at this point in the history
  • Loading branch information
PseudoElement committed Dec 16, 2024
2 parents 8f88b05 + 7b2eeca commit 1398a4a
Show file tree
Hide file tree
Showing 23 changed files with 337 additions and 134 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@safe-global/safe-apps-sdk": "^9.0.0",
"@sentry/angular-ivy": "^7.112.2",
"@sentry/wizard": "^3.22.1",
"@solana/web3.js": "^1.36.0",
"@solana/web3.js": "1.89.1",
"@spindl-xyz/attribution": "^1.8.0",
"@taiga-ui/addon-mobile": "^3.46.0",
"@taiga-ui/addon-table": "~3.46.0",
Expand Down Expand Up @@ -84,7 +84,7 @@
"ng-inline-svg-2": "^15.0.1",
"ngx-cookie-service": "^16.0.0",
"querystring-es3": "^0.2.1",
"rubic-sdk": "5.47.2",
"rubic-sdk": "5.48.1",
"rxjs": "7.8.1",
"ts-cacheable": "^1.0.5",
"viem": "^1.21.1",
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class AppComponent implements AfterViewInit {
this.setupLanguage();

this.initApp();
this.spindlService.initSpindlAds().then();
this.spindlService.initSpindlAds();
}

ngAfterViewInit() {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ const defaultSrc = 'assets/images/icons/navigation/';
type Section = 'Trade' | 'More' | 'Social' | 'Legal & Privacy';

export const NAVIGATION_LIST = [
{
translateKey: 'Swap & Earn',
type: 'internal',
link: ROUTE_PATH.AIRDROP,
imagePath: `assets/images/rbc.svg`
},
{
translateKey: 'Token Claim',
type: 'external',
Expand Down
7 changes: 0 additions & 7 deletions src/app/core/header/components/header/header.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,6 @@
<!-- <div routerLink="/revoke-approval">Revoke Approval</div>-->
<!-- </button>-->

<ng-container *ngIf="!useLargeIframe">
<app-points-button
class="rubic-header__point-button"
*ngIf="currentUser$ | async"
></app-points-button>
</ng-container>

<!-- Uncomment when light theme ready -->
<!-- <button-->
<!-- class="theme-switcher"-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
}

app-rubic-menu-toggler,
app-points-button,
app-language-selector,
app-history-button {
display: none;
Expand Down
2 changes: 0 additions & 2 deletions src/app/core/header/header.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import { MobileUserProfileComponent } from './components/header/components/mobil
import { TuiDestroyService } from '@taiga-ui/cdk';
import { ClipboardModule } from '@angular/cdk/clipboard';
import { MobileNavigationMenuComponent } from './components/header/components/mobile-navigation-menu/mobile-navigation-menu.component';
import { PointsButtonComponent } from './components/header/components/points-button/points-button.component';
import { LogoComponent } from './components/header/components/logo/logo.component';
import { LanguageSelectorComponent } from './components/header/components/language-selector/language-selector.component';
import { SettingsComponent } from '@core/header/components/header/components/settings/settings.component';
Expand All @@ -64,7 +63,6 @@ import { BannerZeroFeesComponent } from './components/header/components/banner-z
RubicMenuTogglerComponent,
MobileUserProfileComponent,
MobileNavigationMenuComponent,
PointsButtonComponent,
LogoComponent,
LanguageSelectorComponent,
SettingsComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface OnChainTradeCreationToBackend {
expected_amount: string;
mevbot_protection: boolean;
receiver: string;
pretrade_id: string;
hash?: string;
from_token?: string;
to_token?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,22 @@ export class CnPreviewSwapComponent {
gasData = trade.gasFeeInfo;
}

if (!gasData || !gasData.gasLimit) {
return null;
}
if (!gasData) return null;

const blockchain = trade.from.blockchain;
const nativeToken = nativeTokensList[blockchain];
const gasLimit = gasData.gasLimit.multipliedBy(gasData.gasPrice);

let gasFeeWei = null;
if (gasData.gasLimit) {
gasFeeWei = gasData.gasLimit.multipliedBy(gasData.gasPrice ?? 0);
} else if (gasData.totalGas) {
gasFeeWei = Web3Pure.fromWei(gasData.totalGas, nativeToken.decimals);
}

if (!gasFeeWei) return null;

return {
amount: Web3Pure.fromWei(gasLimit, trade.from.decimals),
amount: Web3Pure.fromWei(gasFeeWei, nativeToken.decimals),
symbol: nativeToken.symbol
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Web3Pure
} from 'rubic-sdk';
import { firstValueFrom, Observable } from 'rxjs';
import { delay } from 'rxjs/operators';
import { delay, map } from 'rxjs/operators';
import { AuthService } from '@core/services/auth/auth.service';
import { WalletConnectorService } from '@core/services/wallets/wallet-connector-service/wallet-connector.service';
import { TUI_IS_MOBILE } from '@taiga-ui/cdk';
Expand Down Expand Up @@ -83,7 +83,11 @@ export class CrossChainApiService {
* Sends request to add trade.
* @return InstantTradesResponseApi Instant trade object.
*/
public async createTrade(hash: string, trade: CrossChainTrade): Promise<void> {
public async createTrade(
hash: string,
trade: CrossChainTrade,
preTradeId?: string
): Promise<void> {
const {
fromBlockchain,
toBlockchain,
Expand Down Expand Up @@ -119,6 +123,7 @@ export class CrossChainApiService {
this.window.location !== this.window.parent.location
? this.window.document.referrer
: this.window.document.location.href,
...(preTradeId && { pretrade_id: preTradeId }),
...(trade instanceof ChangenowCrossChainTrade && { changenow_id: trade.changenowId }),
...('rangoRequestId' in trade && { rango_request_id: trade.rangoRequestId }),
...('squidrouterRequestId' in trade && {
Expand Down Expand Up @@ -162,4 +167,52 @@ export class CrossChainApiService {
})
.subscribe();
}

public async sendPreTradeInfo(trade: CrossChainTrade): Promise<string> {
const {
fromBlockchain,
toBlockchain,
fromAmount,
fromAddress,
fromDecimals,
toAmount,
toDecimals,
toAddress
} = TradeParser.getCrossChainSwapParams(trade);
const referral = this.sessionStorage.getItem('referral');
const slippage = trade.getTradeInfo().slippage;

const preTradeInfo = {
price_impact: trade.getTradeInfo().priceImpact,
slippage,
wallet_name: this.walletConnectorService.provider.walletName,
device_type: this.isMobile ? 'mobile' : 'desktop',
expected_amount: Web3Pure.toWei(toAmount, toDecimals),
mevbot_protection: this.settingsService.crossChainRoutingValue.useMevBotProtection,
to_amount_min: Web3Pure.toWei(trade.toTokenAmountMin, toDecimals),
from_network: TO_BACKEND_BLOCKCHAINS[fromBlockchain],
to_network: TO_BACKEND_BLOCKCHAINS[toBlockchain],
provider: TO_BACKEND_CROSS_CHAIN_PROVIDERS[trade.type],
from_token: fromAddress,
to_token: toAddress,
from_amount: Web3Pure.toWei(fromAmount, fromDecimals),
to_amount: Web3Pure.toWei(toAmount, toDecimals),
user: this.authService.userAddress,
receiver: this.targetNetworkAddressService.address || this.authService.userAddress,
domain:
this.window.location !== this.window.parent.location
? this.window.document.referrer
: this.window.document.location.href,
...(referral && { influencer: referral })
};

return firstValueFrom(
this.httpService
.post<{ pretrade_id: string }>('v2/trades/crosschain/pretrade_new', preTradeInfo)
.pipe(
delay(1000),
map(res => res.pretrade_id)
)
);
}
}
17 changes: 12 additions & 5 deletions src/app/features/trade/services/cross-chain/cross-chain.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ import { CrossChainCalculatedTradeData } from '@features/trade/models/cross-chai
import { SWAP_PROVIDER_TYPE } from '@features/trade/models/swap-provider-type';
import { TradeParser } from '@features/trade/utils/trade-parser';
import { SessionStorageService } from '@core/services/session-storage/session-storage.service';
import { AirdropPointsService } from '@app/shared/services/airdrop-points-service/airdrop-points.service';
import { CALCULATION_TIMEOUT_MS } from '../../constants/calculation';
import { FormsTogglerService } from '../forms-toggler/forms-toggler.service';
import { CCR_LONG_TIMEOUT_CHAINS } from './ccr-long-timeout-chains';
import { ProxyFeeService } from '@features/trade/services/proxy-fee-service/proxy-fee.service';
import { IframeService } from '@app/core/services/iframe-service/iframe.service';
Expand Down Expand Up @@ -84,8 +82,6 @@ export class CrossChainService {
private readonly authService: AuthService,
private readonly gtmService: GoogleTagManagerService,
private readonly gasService: GasService,
private readonly airdropPointsService: AirdropPointsService,
private readonly formsTogglerService: FormsTogglerService,
private readonly proxyService: ProxyFeeService,
private readonly iframeService: IframeService
) {}
Expand Down Expand Up @@ -282,11 +278,13 @@ export class CrossChainService {
]);
await this.handlePreSwapModal(trade);

const preTradeId = await this.sendPreTradeInfo(trade);

let transactionHash: string;
const onTransactionHash = (txHash: string) => {
transactionHash = txHash;
callbackOnHash?.(txHash);
this.crossChainApiService.createTrade(txHash, trade);
this.crossChainApiService.createTrade(txHash, trade, preTradeId);

this.notifyGtmAfterSignTx(
txHash,
Expand Down Expand Up @@ -510,4 +508,13 @@ export class CrossChainService {

return disabledTradesTypes;
}

private async sendPreTradeInfo(trade: CrossChainTrade): Promise<string | null> {
try {
const preTradeId = await this.crossChainApiService.sendPreTradeInfo(trade);
return preTradeId;
} catch {
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Inject, Injectable } from '@angular/core';
import { firstValueFrom, Observable } from 'rxjs';
import { delay } from 'rxjs/operators';
import { delay, map } from 'rxjs/operators';
import { OnChainTradeCreationToBackend } from '@core/services/backend/instant-trades-api/models/instant-trades-post-api';
import { InstantTradesResponseApi } from '@core/services/backend/instant-trades-api/models/instant-trades-response-api';
import { InstantTradeBotRequest } from '@core/services/backend/instant-trades-api/models/instant-trades-bot-request';
Expand Down Expand Up @@ -72,7 +72,8 @@ export class OnChainApiService {
public createTrade(
hash: string,
provider: OnChainTradeType,
trade: OnChainTrade
trade: OnChainTrade,
preTradeId?: string
): Observable<InstantTradesResponseApi> {
const { blockchain, fromAmount, fromAddress, fromDecimals, toAmount, toDecimals, toAddress } =
TradeParser.getItSwapParams(trade);
Expand Down Expand Up @@ -104,6 +105,7 @@ export class OnChainApiService {
user: this.authService.userAddress,
receiver: this.targetNetworkAddressService.address || this.authService.userAddress,
hash,
...(preTradeId && { pretrade_id: preTradeId }),
...(referral && { influencer: referral }),
...(swapId && { swap_id: swapId })
};
Expand Down Expand Up @@ -171,4 +173,39 @@ export class OnChainApiService {
}
});
}

public sendPreTradeInfo(trade: OnChainTrade): Promise<string> {
const { blockchain, fromAmount, fromAddress, fromDecimals, toAmount, toDecimals, toAddress } =
TradeParser.getItSwapParams(trade);
const referral = this.sessionStorage.getItem('referral');
const backendProvider = TO_BACKEND_ON_CHAIN_PROVIDERS[trade.type];

const preTradeInfo: Omit<OnChainTradeCreationToBackend, 'pretrade_id'> = {
price_impact: trade.getTradeInfo().priceImpact,
walletName: this.walletConnectorService.provider.walletName,
deviceType: this.isMobile ? 'mobile' : 'desktop',
slippage: trade.slippageTolerance,
expected_amount: Web3Pure.toWei(toAmount, toDecimals),
mevbot_protection: this.settingsService.instantTradeValue.useMevBotProtection,
to_amount_min: trade.toTokenAmountMin.stringWeiAmount,
network: TO_BACKEND_BLOCKCHAINS[blockchain],
provider: backendProvider,
from_token: fromAddress,
to_token: toAddress,
from_amount: Web3Pure.toWei(fromAmount, fromDecimals),
to_amount: Web3Pure.toWei(toAmount, toDecimals),
user: this.authService.userAddress,
receiver: this.targetNetworkAddressService.address || this.authService.userAddress,
...(referral && { influencer: referral })
};

return firstValueFrom(
this.httpService
.post<{ pretrade_id: string }>('v2/trades/onchain/pretrade_new', preTradeInfo)
.pipe(
delay(1000),
map(res => res.pretrade_id)
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ const onChainBlacklist: Record<SupportedOnChainNetworks, OnChainTradeType[]> = {
[BLOCKCHAIN_NAME.CORE]: [],
[BLOCKCHAIN_NAME.BAHAMUT]: [],
[BLOCKCHAIN_NAME.BITLAYER]: [],
[BLOCKCHAIN_NAME.GRAVITY]: []
[BLOCKCHAIN_NAME.GRAVITY]: [],
[BLOCKCHAIN_NAME.UNICHAIN_SEPOLIA_TESTNET]: []
};

export const onChainBlacklistProviders: OnChainTradeType[] = [
Expand Down
Loading

0 comments on commit 1398a4a

Please sign in to comment.