Skip to content

Commit

Permalink
feat(frontend): remove BTC flag from stores and services
Browse files Browse the repository at this point in the history
  • Loading branch information
DenysKarmazynDFINITY committed Oct 28, 2024
1 parent 12bbc78 commit 77de902
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 49 deletions.
3 changes: 1 addition & 2 deletions src/frontend/src/lib/components/core/Loader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { debounce, isNullish } from '@dfinity/utils';
import { onMount } from 'svelte';
import { fade } from 'svelte/transition';
import { NETWORK_BITCOIN_ENABLED } from '$env/networks.btc.env';
import { loadErc20Tokens } from '$eth/services/erc20.services';
import { loadIcrcTokens } from '$icp/services/icrc.services';
import banner from '$lib/assets/banner.svg';
Expand Down Expand Up @@ -78,7 +77,7 @@
const debounceLoadBtcAddressRegtest = debounce(loadBtcAddressRegtest);
$: {
if (NETWORK_BITCOIN_ENABLED && $testnets && isNullish($btcAddressTestnet)) {
if ($testnets && isNullish($btcAddressTestnet)) {
debounceLoadBtcAddressTestnet();
if (LOCAL) {
debounceLoadBtcAddressRegtest();
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/src/lib/components/guard/AddressGuard.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import { NETWORK_BITCOIN_ENABLED } from '$env/networks.btc.env';
import { validateBtcAddressMainnet, validateEthAddress } from '$lib/services/address.services';
import { initSignerAllowance } from '$lib/services/loader.services';
import { btcAddressMainnetStore, ethAddressStore } from '$lib/stores/address.store';
Expand All @@ -26,7 +25,7 @@
await Promise.allSettled([
validateEthAddress($ethAddressStore),
...(NETWORK_BITCOIN_ENABLED ? [validateBtcAddressMainnet($btcAddressMainnetStore)] : [])
validateBtcAddressMainnet($btcAddressMainnetStore)
]);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { nonNullish } from '@dfinity/utils';
import { NETWORK_BITCOIN_ENABLED } from '$env/networks.btc.env';
import { BTC_MAINNET_NETWORK_ID, ETHEREUM_NETWORK_ID, ICP_NETWORK_ID } from '$env/networks.env';
import { BTC_MAINNET_TOKEN } from '$env/tokens.btc.env';
import { ICP_TOKEN } from '$env/tokens.env';
Expand All @@ -20,7 +19,7 @@
$token?.buy?.onramperId ??
($networkEthereum
? $ethereumToken.buy?.onramperId
: $networkBitcoin && NETWORK_BITCOIN_ENABLED
: $networkBitcoin
? BTC_MAINNET_TOKEN.buy?.onramperId
: ICP_TOKEN.buy?.onramperId) ??
ICP_TOKEN.buy?.onramperId ??
Expand Down
71 changes: 34 additions & 37 deletions src/frontend/src/lib/components/receive/ReceiveAddresses.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
import { NETWORK_BITCOIN_ENABLED } from '$env/networks.btc.env';
import { BTC_MAINNET_TOKEN, BTC_REGTEST_TOKEN, BTC_TESTNET_TOKEN } from '$env/tokens.btc.env';
import { ETHEREUM_TOKEN, ICP_TOKEN } from '$env/tokens.env';
import { icpAccountIdentifierText, icrcAccountIdentifierText } from '$icp/derived/ic.derived';
Expand Down Expand Up @@ -73,60 +72,58 @@
>
</ReceiveAddressWithLogo>

{#if NETWORK_BITCOIN_ENABLED}
<div class="my-6">
<Hr />
</div>
<div class="my-6">
<Hr />
</div>

<ReceiveAddressWithLogo
on:click={() =>
displayQRCode({
address: $btcAddressMainnet ?? '',
addressLabel: $i18n.receive.bitcoin.text.bitcoin_address,
addressToken: BTC_MAINNET_TOKEN
})}
address={$btcAddressMainnet}
token={BTC_MAINNET_TOKEN}
qrCodeAriaLabel={$i18n.receive.bitcoin.text.display_bitcoin_address_qr}
copyAriaLabel={$i18n.receive.bitcoin.text.bitcoin_address_copied}
testId={RECEIVE_TOKENS_MODAL_BTC_SECTION}
>
{$i18n.receive.bitcoin.text.bitcoin_address}
</ReceiveAddressWithLogo>

{#if $testnets}
<ReceiveAddressWithLogo
on:click={() =>
displayQRCode({
address: $btcAddressMainnet ?? '',
addressLabel: $i18n.receive.bitcoin.text.bitcoin_address,
addressToken: BTC_MAINNET_TOKEN
address: $btcAddressTestnet ?? '',
addressLabel: $i18n.receive.bitcoin.text.bitcoin_testnet_address,
addressToken: BTC_TESTNET_TOKEN
})}
address={$btcAddressMainnet}
token={BTC_MAINNET_TOKEN}
address={$btcAddressTestnet}
token={BTC_TESTNET_TOKEN}
qrCodeAriaLabel={$i18n.receive.bitcoin.text.display_bitcoin_address_qr}
copyAriaLabel={$i18n.receive.bitcoin.text.bitcoin_address_copied}
testId={RECEIVE_TOKENS_MODAL_BTC_SECTION}
>
{$i18n.receive.bitcoin.text.bitcoin_address}
{$i18n.receive.bitcoin.text.bitcoin_testnet_address}
</ReceiveAddressWithLogo>

{#if $testnets}
{#if LOCAL}
<!-- Same address for Regtest and for Testnet are used. -->
<ReceiveAddressWithLogo
on:click={() =>
displayQRCode({
address: $btcAddressTestnet ?? '',
addressLabel: $i18n.receive.bitcoin.text.bitcoin_testnet_address,
addressToken: BTC_TESTNET_TOKEN
address: $btcAddressRegtest ?? '',
addressLabel: $i18n.receive.bitcoin.text.bitcoin_regtest_address,
addressToken: BTC_REGTEST_TOKEN
})}
address={$btcAddressTestnet}
token={BTC_TESTNET_TOKEN}
address={$btcAddressRegtest}
token={BTC_REGTEST_TOKEN}
qrCodeAriaLabel={$i18n.receive.bitcoin.text.display_bitcoin_address_qr}
copyAriaLabel={$i18n.receive.bitcoin.text.bitcoin_address_copied}
>
{$i18n.receive.bitcoin.text.bitcoin_testnet_address}
{$i18n.receive.bitcoin.text.bitcoin_regtest_address}
</ReceiveAddressWithLogo>

{#if LOCAL}
<!-- Same address for Regtest and for Testnet are used. -->
<ReceiveAddressWithLogo
on:click={() =>
displayQRCode({
address: $btcAddressRegtest ?? '',
addressLabel: $i18n.receive.bitcoin.text.bitcoin_regtest_address,
addressToken: BTC_REGTEST_TOKEN
})}
address={$btcAddressRegtest}
token={BTC_REGTEST_TOKEN}
qrCodeAriaLabel={$i18n.receive.bitcoin.text.display_bitcoin_address_qr}
copyAriaLabel={$i18n.receive.bitcoin.text.bitcoin_address_copied}
>
{$i18n.receive.bitcoin.text.bitcoin_regtest_address}
</ReceiveAddressWithLogo>
{/if}
{/if}
{/if}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as btcEnv from '$env/networks.btc.env';
import * as api from '$lib/api/backend.api';
import { CanisterInternalError } from '$lib/canisters/errors';
import AddressGuard from '$lib/components/guard/AddressGuard.svelte';
Expand Down Expand Up @@ -73,11 +72,6 @@ describe('AddressGuard', () => {
});

describe('Validate addresses', () => {
beforeEach(() => {
// TODO: to be removed when the flag NETWORK_BITCOIN_ENABLED gets removed and Bitcoin becomes default.
vi.spyOn(btcEnv, 'NETWORK_BITCOIN_ENABLED', 'get').mockReturnValue(true);
});

describe('Signer allowance not loaded', () => {
it('should not call validate eth address if signer allowance is not loaded', () => {
render(AddressGuard);
Expand Down

0 comments on commit 77de902

Please sign in to comment.