Skip to content

Commit

Permalink
Merge pull request #3482 from Cryptorubic/semi-centralized
Browse files Browse the repository at this point in the history
Centralization
  • Loading branch information
IDIDOS authored Jan 23, 2025
2 parents 6f15a3e + 38a1d82 commit a69f2f5
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"ngx-cookie-service": "^16.0.0",
"querystring-es3": "^0.2.1",
"rpc-websockets": "7.9.0",
"rubic-sdk": "5.50.4",
"rubic-sdk": "5.50.5",
"rxjs": "7.8.1",
"ts-cacheable": "^1.0.5",
"viem": "^1.21.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class TokensListElementComponent {
}

public get securityStatus(): TokenSecurityStatus {
if (GO_PLUS_AVAILABLE_NETWORKS.includes(this.token.blockchain) === false) {
if (!GO_PLUS_AVAILABLE_NETWORKS.includes(this.token.blockchain)) {
return TokenSecurityStatus.UNSUPPORTED_BLOCKCHAIN;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ export const GO_PLUS_AVAILABLE_NETWORKS: BlockchainName[] = [
BLOCKCHAIN_NAME.CRONOS,
BLOCKCHAIN_NAME.GNOSIS,
BLOCKCHAIN_NAME.TRON,
BLOCKCHAIN_NAME.ZK_FAIR
BLOCKCHAIN_NAME.ZK_FAIR,
BLOCKCHAIN_NAME.BASE
];
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,23 @@

<tui-expand [expanded]="expanded">
<ng-template tuiExpandContent>
<app-route-element
[tradeType]="tradeState.tradeType"
[routes]="tradeState.routes"
></app-route-element>
<div class="element__expandable">
<div *ngIf="tradeState.centralizationStatus" class="element__expandable-status">
<img
class="element__expan dable-status-icon"
[src]="'assets/images/icons/' + tradeState.centralizationStatus + '.png'"
width="16"
height="16"
alt="centralization"
/>
<p class="element__expandable-status-text">{{ tradeState.centralizationStatus }}</p>
</div>

<app-route-element
[tradeType]="tradeState.tradeType"
[routes]="tradeState.routes"
></app-route-element>
</div>
</ng-template>
</tui-expand>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,27 @@
gap: var(--tui-padding-xs);
align-items: flex-end;
}

&__expandable {
@include flex(column, normal, normal);
margin-top: var(--tui-padding-s);

&-status {
@include flex(row, center, normal);
gap: 7px;


&-text {
color: var(--tui-text-03);
line-height: 10px;
}
}
}
}

app-route-element {
display: block;
margin-top: var(--tui-padding-l);
// margin-top: var(--tui-padding-s);
}

@include b($mobile-md) {
Expand Down
21 changes: 21 additions & 0 deletions src/app/features/trade/constants/centralization-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { CROSS_CHAIN_TRADE_TYPE, CrossChainTradeType, OnChainTradeType } from 'rubic-sdk';

export const CENTRALIZATION_STATUS = {
CENTRALIZED: 'centralized',
DECENTRALIZED: 'decentralized',
SEMI_CENTRALIZED: 'semi-centralized'
} as const;

export type CentralizationStatus =
(typeof CENTRALIZATION_STATUS)[keyof typeof CENTRALIZATION_STATUS];

export const CENTRALIZATION_CONFIG: Partial<Record<CrossChainTradeType, CentralizationStatus>> = {
[CROSS_CHAIN_TRADE_TYPE.SIMPLE_SWAP]: CENTRALIZATION_STATUS.SEMI_CENTRALIZED,
[CROSS_CHAIN_TRADE_TYPE.CHANGENOW]: CENTRALIZATION_STATUS.SEMI_CENTRALIZED
};

export function hasCentralizationStatus(
tradeType: CrossChainTradeType | OnChainTradeType
): tradeType is keyof typeof CENTRALIZATION_CONFIG {
return Object.keys(CENTRALIZATION_CONFIG).some(type => type === tradeType);
}
2 changes: 2 additions & 0 deletions src/app/features/trade/models/trade-state.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WrappedSdkTrade } from '@features/trade/models/wrapped-sdk-trade';
import { CrossChainTrade, OnChainTrade, RubicStep } from 'rubic-sdk';
import { CentralizationStatus } from '../constants/centralization-status';

interface TradefullState {
trade: WrappedSdkTrade['trade'];
Expand All @@ -24,6 +25,7 @@ export type TradeState = (TradefullState | TradelessState) & {
needAuthWallet?: boolean;
routes: RubicStep[];
badges?: BadgeInfoForComponent[];
centralizationStatus: CentralizationStatus;
};

export interface BadgeInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ export const defaultTradeState: SelectedTrade = {
},
routes: [],
selectedByUser: false,
status: TRADE_STATUS.NOT_INITIATED
status: TRADE_STATUS.NOT_INITIATED,
centralizationStatus: null,
badges: []
};
20 changes: 18 additions & 2 deletions src/app/features/trade/services/swaps-state/swaps-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ import { HeaderStore } from '@core/header/services/header.store';
import { SPECIFIC_BADGES_FOR_PROVIDERS } from './constants/specific-badges-for-trades';
import { SPECIFIC_BADGES_FOR_CHAINS } from './constants/specific-badges-for-chains';
import { AlternativeRoutesService } from '../alternative-route-api-service/alternative-routes.service';
import {
CENTRALIZATION_CONFIG,
CentralizationStatus,
hasCentralizationStatus
} from '../../constants/centralization-status';

@Injectable()
export class SwapsStateService {
Expand Down Expand Up @@ -156,7 +161,8 @@ export class SwapsStateService {
needAuthWallet,
tradeType: wrappedTrade.tradeType,
tags: { isBest: false, cheap: false },
routes: []
routes: [],
centralizationStatus: null
}
: {
error: wrappedTrade?.error,
Expand All @@ -166,7 +172,8 @@ export class SwapsStateService {
tradeType: wrappedTrade.tradeType,
tags: { isBest: false, cheap: false },
routes: trade.getTradeInfo().routePath || [],
badges: this.setSpecificBadges(trade)
badges: this.setSpecificBadges(trade),
centralizationStatus: this.setCentralizationStatus(trade)
};

let currentTrades = this._tradesStore$.getValue();
Expand Down Expand Up @@ -492,4 +499,13 @@ export class SwapsStateService {

return tradeSpecificBadges;
}

private setCentralizationStatus(
trade: CrossChainTrade | OnChainTrade
): CentralizationStatus | null {
if (hasCentralizationStatus(trade.type)) {
return CENTRALIZATION_CONFIG[trade.type];
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,25 @@ export class TradeInfoManager {
}

public getGasData(trade: CrossChainTrade | OnChainTrade): AppGasData | null {
if (!('gasData' in trade) && !('gasFeeInfo' in trade)) return null;
const estimatedGasInWei = trade.getTradeInfo().estimatedGas;

if ((!('gasData' in trade) && !('gasFeeInfo' in trade)) || !estimatedGasInWei) return null;

const blockchain = trade.from.blockchain;
const nativeToken = nativeTokensList[blockchain];
const nativeTokenPrice = this.tokensStoreService.tokens.find(token =>
compareTokens(token, { blockchain, address: nativeToken.address })
).price;

if (estimatedGasInWei) {
const estimatedGas = Web3Pure.fromWei(estimatedGasInWei, nativeToken.decimals);
return {
amount: estimatedGas,
amountInUsd: estimatedGas.multipliedBy(nativeTokenPrice),
symbol: nativeToken.symbol
};
}

let gasFeeNonWei = null;
if (trade instanceof EvmCrossChainTrade) {
gasFeeNonWei = this.getCcrGasFee(trade, nativeToken);
Expand Down
Binary file added src/assets/images/icons/decentralized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/images/icons/semi-centralized.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17559,10 +17559,10 @@ rpc-websockets@^9.0.2:
bufferutil "^4.0.1"
utf-8-validate "^5.0.2"

[email protected].4:
version "5.50.4"
resolved "https://registry.yarnpkg.com/rubic-sdk/-/rubic-sdk-5.50.4.tgz#ee1ae4228293719567e7ab7c14b7c6710d5dc556"
integrity sha512-F8HJ543RN+YRj6HblLKeeWg0db+VB3e/LK8QTYQ5MVsi2H1i9/qfquYQtKaU5V9QsJ7ekxV2VTxGFfxHBeEgrA==
[email protected].5:
version "5.50.5"
resolved "https://registry.yarnpkg.com/rubic-sdk/-/rubic-sdk-5.50.5.tgz#293051f42d931129e16118928e3a34bc4f0a8873"
integrity sha512-MmSABhp5lnUJje5tooxKuEmQ2Lc5zpU/tz91U/ZZbfRUgxZAdOFBrpgnyI2mP28TsG5xaxcS6cmMUfE08YiipA==
dependencies:
"@1inch/limit-order-protocol-utils" "3.0.1"
"@arbitrum/sdk" "^3.1.3"
Expand Down

0 comments on commit a69f2f5

Please sign in to comment.