From 70878dc10f3af4181a218cebd1b04151478f88b2 Mon Sep 17 00:00:00 2001 From: Saad Ahmed <48211799+saadjhk@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:40:58 +0200 Subject: [PATCH] fix: removed hardcoded Environment (#214) Changing Environment doesn't work on Widget ## Description Removal of hardcoded `Testnet` in widget --- .../src/controllers/transfers/fungible-token-transfer.ts | 5 ++++- packages/widget/src/widget.ts | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/widget/src/controllers/transfers/fungible-token-transfer.ts b/packages/widget/src/controllers/transfers/fungible-token-transfer.ts index 5024fb8f..b43b72cf 100644 --- a/packages/widget/src/controllers/transfers/fungible-token-transfer.ts +++ b/packages/widget/src/controllers/transfers/fungible-token-transfer.ts @@ -37,6 +37,7 @@ import { estimateEvmTransactionsGasCost, estimateSubstrateGas } from '../../utils/gas'; +import type { FungibleTokenTransfer } from '../../components'; import { buildEvmFungibleTransactions, executeNextEvmTransaction } from './evm'; import { buildSubstrateFungibleTransactions, @@ -95,7 +96,7 @@ export class FungibleTokenTransferController implements ReactiveController { protected executeSubstrateTransaction = executeNextSubstrateTransaction; protected config: Config; - protected env: Environment = Environment.MAINNET; + protected env: Environment; //source network chain id -> Route[] protected routesCache: Map = new Map(); @@ -146,6 +147,8 @@ export class FungibleTokenTransferController implements ReactiveController { constructor(host: ReactiveElement) { (this.host = host).addController(this); this.config = new Config(); + this.env = + (this.host as FungibleTokenTransfer).environment ?? Environment.MAINNET; this.walletContext = new ContextConsumer(host, { context: walletContext, diff --git a/packages/widget/src/widget.ts b/packages/widget/src/widget.ts index 11c7c057..f6c7f1d6 100644 --- a/packages/widget/src/widget.ts +++ b/packages/widget/src/widget.ts @@ -84,7 +84,7 @@ class SygmaProtocolWidget connectedCallback(): void { super.connectedCallback(); - const env = import.meta.env.VITE_BRIDGE_ENV ?? Environment.MAINNET; + const env = this.environment ?? Environment.MAINNET; if (Object.values(Environment).includes(env as Environment)) { this.environment = env as Environment; } else { @@ -120,7 +120,7 @@ class SygmaProtocolWidget .environment=${this.environment as Environment} .onSourceNetworkSelected=${(domain: Domain) => (this.sourceNetwork = domain)} - environment=${Environment.TESTNET} + environment=${this.environment ?? Environment.MAINNET} .whitelistedSourceNetworks=${this.whitelistedSourceNetworks} .whitelistedDestinationNetworks=${this .whitelistedDestinationNetworks}