Skip to content

Commit

Permalink
feat: List localhost:8545 only in dev mode (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
fegbert authored Feb 23, 2022
1 parent fb4b4bd commit 5a2e06e
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 20 deletions.
9 changes: 8 additions & 1 deletion core/src/constants/NETWORKS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,11 @@ export const getNetworkTitleByChainId = function (chainId: string | undefined) {
return NETWORK_TITLES[chainId];
};

export default NETWORKS;
export const getNetworks = function (isDev: boolean): Record<string, NetworkConfig> {
if (isDev) {
return NETWORKS;
}
//eslint-disable-next-line @typescript-eslint/no-unused-vars
const { localhost, ...otherNetworks } = NETWORKS;
return otherNetworks;
};
10 changes: 10 additions & 0 deletions frontend/components/layout/Header.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ storiesOf('Layout/Header', module)
@update:isExplanationsShown="updateIsExplanationsShown"
/>`,
}))
.add('Dev Mode', () => ({
...common,
template: `<Header
:network.sync="network"
:isExplanationsShown.sync="isExplanationsShown"
@update:network="updateNetwork"
@update:isExplanationsShown="updateIsExplanationsShown"
is-dev
/>`,
}))
.add('Unified Auctions Page', () => ({
...common,
template: `<Header
Expand Down
5 changes: 5 additions & 0 deletions frontend/components/layout/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<NetworkSelector
v-if="!isUnifiedPage && !isMinimal"
:network="network"
:is-dev="isDev"
@update:network="$emit('update:network', $event)"
/>

Expand Down Expand Up @@ -109,6 +110,10 @@ export default Vue.extend({
type: String,
default: undefined,
},
isDev: {
type: Boolean,
default: false,
},
},
computed: {
isUnifiedPage() {
Expand Down
13 changes: 9 additions & 4 deletions frontend/components/modals/ChangePageNetworkModal.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ const common = {
},
};

storiesOf('Modals/ChangePageNetworkModal', module).add('Default', () => ({
...common,
template: '<ChangePageNetworkModal :invalid-network="chainId" @setNetwork="setNetwork" />',
}));
storiesOf('Modals/ChangePageNetworkModal', module)
.add('Default', () => ({
...common,
template: '<ChangePageNetworkModal :invalid-network="chainId" @setNetwork="setNetwork" />',
}))
.add('Dev Mode', () => ({
...common,
template: '<ChangePageNetworkModal :invalid-network="chainId" @setNetwork="setNetwork" is-dev />',
}));
8 changes: 6 additions & 2 deletions frontend/components/modals/ChangePageNetworkModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<script lang="ts">
import { Modal, Alert } from 'ant-design-vue';
import Vue from 'vue';
import NETWORKS from 'auctions-core/src/constants/NETWORKS';
import { getNetworks } from 'auctions-core/src/constants/NETWORKS';
export default Vue.extend({
name: 'ChangePageNetworkModal',
Expand All @@ -40,11 +40,15 @@ export default Vue.extend({
type: String,
default: '',
},
isDev: {
type: Boolean,
default: false,
},
},
data() {
return {
options: [
...Object.entries(NETWORKS).map(([name, propeties]) => {
...Object.entries(getNetworks(this.isDev)).map(([name, propeties]) => {
return { label: propeties.title, value: name };
}),
],
Expand Down
12 changes: 8 additions & 4 deletions frontend/components/modals/ChangeWalletNetworkModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<script lang="ts">
import { Modal, Alert } from 'ant-design-vue';
import Vue from 'vue';
import NETWORKS from 'auctions-core/src/constants/NETWORKS';
import { getNetworks } from 'auctions-core/src/constants/NETWORKS';
import BaseButton from '~/components/common/BaseButton';
export default Vue.extend({
Expand All @@ -47,19 +47,23 @@ export default Vue.extend({
type: String,
required: true,
},
isDev: {
type: Boolean,
default: false,
},
},
data() {
return {
options: [
...Object.entries(NETWORKS).map(([name, propeties]) => {
...Object.entries(getNetworks(this.isDev)).map(([name, propeties]) => {
return { label: propeties.title, value: name };
}),
],
};
},
computed: {
isWalletNetworkSuppotedByTheWebsite(): string {
return !!NETWORKS[this.invalidNetwork];
isWalletNetworkSuppotedByTheWebsite(): boolean {
return !!getNetworks(this.isDev)[this.invalidNetwork];
},
},
});
Expand Down
6 changes: 3 additions & 3 deletions frontend/components/utils/FormatAddress.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<script lang="ts">
import Vue from 'vue';
import NETWORKS from 'auctions-core/src/constants/NETWORKS';
import { getNetworkConfigByType } from 'auctions-core/src/constants/NETWORKS';
const TRIM_POSITION_FROM_START = 5;
const TRIM_POSITION_FROM_END = 4;
Expand Down Expand Up @@ -60,8 +60,8 @@ export default Vue.extend({
return 'https://etherscan.io';
}
const network = this.$store.getters['network/getMakerNetwork'];
if (NETWORKS[network]) {
return NETWORKS[network].etherscanUrl;
if (getNetworkConfigByType(network)) {
return getNetworkConfigByType(network).etherscanUrl;
}
return 'https://etherscan.io';
},
Expand Down
13 changes: 9 additions & 4 deletions frontend/components/utils/NetworkSelector.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ const common = {
},
};

storiesOf('Utils/NetworkSelector', module).add('Default', () => ({
...common,
template: '<network-selector @select="select"/>',
}));
storiesOf('Utils/NetworkSelector', module)
.add('Default', () => ({
...common,
template: '<network-selector @select="select"/>',
}))
.add('Dev Mode', () => ({
...common,
template: '<network-selector @select="select" is-dev />',
}));
8 changes: 6 additions & 2 deletions frontend/components/utils/NetworkSelector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script lang="ts">
import Vue from 'vue';
import { Icon } from 'ant-design-vue';
import NETWORKS from 'auctions-core/src/constants/NETWORKS';
import { getNetworks } from 'auctions-core/src/constants/NETWORKS';
import Select from '~/components/common/Select.vue';
import { FAKE_NETWORK_NAME } from '~/store/network';
Expand All @@ -24,11 +24,15 @@ export default Vue.extend({
type: String,
default: null,
},
isDev: {
type: Boolean,
default: false,
},
},
data() {
return {
options: [
...Object.entries(NETWORKS).map(([name, propeties]) => {
...Object.entries(getNetworks(this.isDev)).map(([name, propeties]) => {
return { label: propeties.title, value: name as string | null };
}),
{ label: 'Stub data', value: FAKE_NETWORK_NAME },
Expand Down
6 changes: 6 additions & 0 deletions frontend/layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@
:is-wallet-loading="isWalletLoading"
:has-accepted-terms="hasAcceptedTerms"
:staging-banner-url="stagingBannerURL"
:is-dev="isDev"
@changeWalletType="changeWalletType"
@openTermsModal="setTermsModal(true)"
/>
<Nuxt />
<ChangePageNetworkModal
v-if="!isPageNetworkValid"
:invalid-network="getPageNetwork"
:is-dev="isDev"
@setPageNetwork="setPageNetwork"
/>
<ChangeWalletNetworkModal
v-else-if="!isWalletNetworkValid"
:invalid-network="getWalletNetworkTitle"
:page-network="network"
:is-dev="isDev"
@setPageNetwork="setPageNetwork"
@fixWalletNetwork="fixWalletNetwork"
/>
Expand Down Expand Up @@ -93,6 +96,9 @@ export default Vue.extend({
stagingBannerURL() {
return process.env.STAGING_BANNER_URL;
},
isDev() {
return this.$nuxt?.context?.isDev;
},
},
methods: {
...mapActions('network', ['setPageNetwork', 'fixWalletNetwork']),
Expand Down

0 comments on commit 5a2e06e

Please sign in to comment.