Skip to content

Commit

Permalink
SwapModal,MoonpayModal,SimplexModal: disable NIM when network interac…
Browse files Browse the repository at this point in the history
…tions are disabled
  • Loading branch information
danimoh committed Nov 25, 2024
1 parent 8898912 commit d2785dc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
14 changes: 10 additions & 4 deletions src/components/modals/MoonpayModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,22 @@ export default defineComponent({
},
},
setup(props) {
const { config } = useConfig();
const { language } = useSettingsStore().state;
const baseCurrencyCode = useFiatStore().state.currency;
type MoonpayCurrencyCode = CryptoCurrency | 'usdc_polygon' | 'usdt_polygon';
let defaultCurrencyCode: MoonpayCurrencyCode = useAccountStore().state.activeCurrency;
if (defaultCurrencyCode === CryptoCurrency.NIM && config.disableNetworkInteraction) {
defaultCurrencyCode = CryptoCurrency.BTC;
}
if (defaultCurrencyCode === CryptoCurrency.USDC) defaultCurrencyCode = 'usdc_polygon';
if (defaultCurrencyCode === CryptoCurrency.USDT) defaultCurrencyCode = 'usdt_polygon';
const nimAddress = !config.disableNetworkInteraction
// Remove spaces in NIM address, as spaces are invalid URI components
? useAddressStore().state.activeAddress?.replace(/\s/g, '')
: undefined;
// Having a BTC address must be optional, so that the widget also works
// for legacy or non-bitcoin-activated accounts.
const btcAddress = useBtcAddressStore().availableExternalAddresses.value[0] as string | undefined;
Expand All @@ -112,15 +121,12 @@ export default defineComponent({
: undefined;
const walletAddresses = {
// Remove spaces in NIM address, as spaces are invalid URI components
nim: useAddressStore().state.activeAddress?.replace(/\s/g, ''),
...(nimAddress ? { nim: nimAddress } : {}),
...(btcAddress ? { btc: btcAddress } : {}),
...(usdcAddress ? { usdc_polygon: usdcAddress } : {}),
...(usdtAddress ? { usdt_polygon: usdtAddress } : {}),
};
const { config } = useConfig();
const widgetReady = ref(false);
let widget: any;
Expand Down
36 changes: 23 additions & 13 deletions src/components/modals/SimplexModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@
</Tooltip>
<!-- Using v-show here is on purpose: the Simplex widget breaks when removing this element with using v-if -->
<PageBody v-show="showAddressCopyUi" class="copy-address">
<p class="nq-text nq-light-blue">
{{ $t('Copy and paste your address into\nthe Simplex interface below.') }}
</p>
<div class="identicon-container">
<ResizingCopyable :text="currentlyShownAddress">
<div
class="address flex-row"
:class="{'show-identicon': cryptoCurrencyCode === CryptoCurrency.NIM}"
>{{ currentlyShownAddress }}</div>
</ResizingCopyable>
<Identicon v-if="cryptoCurrencyCode === CryptoCurrency.NIM" :address="currentlyShownAddress"/>
</div>
<template v-if="$config.disableNetworkInteraction && cryptoCurrencyCode === CryptoCurrency.NIM">
<p class="nq-text nq-orange">
{{ $t('The Simplex integration is currently disabled while the network is experiencing an '
+ 'outage.') }}
</p>
</template>
<template v-else>
<p class="nq-text nq-light-blue">
{{ $t('Copy and paste your address into\nthe Simplex interface below.') }}
</p>
<div class="identicon-container">
<ResizingCopyable :text="currentlyShownAddress">
<div
class="address flex-row"
:class="{'show-identicon': cryptoCurrencyCode === CryptoCurrency.NIM}"
>{{ currentlyShownAddress }}</div>
</ResizingCopyable>
<Identicon v-if="cryptoCurrencyCode === CryptoCurrency.NIM" :address="currentlyShownAddress"/>
</div>
</template>
</PageBody>
<div class="separator"></div>
<form id="simplex-form" ref="simplex$">
Expand All @@ -31,7 +39,9 @@
<div v-if="mustReload" class="reload-notice flex-column">
{{ $t('Refresh the page to continue.') }}
</div>
<div v-if="showAddressCopyUi" class="copy-over-arrow">
<div v-if="showAddressCopyUi
&& !($config.disableNetworkInteraction && cryptoCurrencyCode === CryptoCurrency.NIM)"
class="copy-over-arrow">
<svg width="162" height="285" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M55.4 24c64 35.8 68.3 151.1 13.3 191.8m12.6 4.2l-15.7-2 1.8-15.7"
stroke="#fff" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
Expand Down
3 changes: 2 additions & 1 deletion src/components/swap/SwapModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,8 @@ export default defineComponent({
// but instead show a maintenance message in the footer.
disabled: (
// The asset is not activated in the active account.
(asset === SwapAsset.BTC && !hasBitcoinAddresses.value)
(asset === SwapAsset.NIM && config.disableNetworkInteraction)
|| (asset === SwapAsset.BTC && !hasBitcoinAddresses.value)
|| (asset === SwapAsset.USDC_MATIC && !hasPolygonAddresses.value)
|| (asset === SwapAsset.USDT_MATIC && !hasPolygonAddresses.value)
) || (
Expand Down

0 comments on commit d2785dc

Please sign in to comment.