Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #1031 #1040

Merged
merged 3 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ import { apiUrl } from './utils/common';
import i18n from './i18n';
import { getConfigValue } from './contracts';
import '@/mixins/general';
import config from '../app-config.json';

Vue.directive('visible', (el, bind) => {
el.style.visibility = bind.value ? 'visible' : 'hidden';
Expand Down Expand Up @@ -139,6 +140,7 @@ export default {
},
$route(to) {
// react to route changes
this.checkChainAndParams();
if(to.path === '/options') {
return this.isOptions = true;
} else this.isOptions = false;
Expand Down Expand Up @@ -166,7 +168,35 @@ export default {
...mapGetters([
'getExchangeTransakUrl'
]),
async checkChainAndParams(){
const currentChain = localStorage.getItem('currentChain') || 'BSC';
const paramChain = this.$router.currentRoute.query.chain;
const supportedChains = config.supportedChains;

if(!paramChain){
this.setChainAndParams(currentChain);
}

//add chain as query param if chain unchanged
if(currentChain === paramChain || !paramChain){
this.setChainAndParams(currentChain);
}

//set chain in localStorage & MM from query param; check if supported
else if (currentChain !== paramChain && supportedChains.includes(paramChain)){
localStorage.setItem('currentChain', paramChain);
await this.configureMetaMask(+getConfigValue('VUE_APP_NETWORK_ID'));
}
},
setChainAndParams(chain){
localStorage.setItem('currentChain', chain);
this.$router.replace(
{
query: Object.assign({ ...this.$route.query }, { chain }),
},
() => {}
);
},
async updateCharacterStamina(id) {
if (this.featureFlagStakeOnly) return;

Expand Down Expand Up @@ -312,6 +342,7 @@ export default {
},

async created() {
this.checkChainAndParams();
try {
await this.initializeStore();
} catch (e) {
Expand All @@ -324,6 +355,8 @@ export default {
throw e;
}



this.pollCharactersStaminaIntervalId = setInterval(async () => {
this.ownCharacters.forEach(async (c) => {
await this.updateCharacterStamina(c.id);
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import axios from 'axios';
import BigNumber from 'bignumber.js';
import Web3 from 'web3';
import config from '../../app-config.json';
import createRouter from '../router';
const router = createRouter();

BigNumber.config({ ROUNDING_MODE: BigNumber.ROUND_DOWN });
BigNumber.config({ EXPONENTIAL_AT: 100 });
Expand All @@ -25,6 +27,12 @@ interface Chain {
for (const [chainName, values] of Object.entries(chains)){
if(+values.VUE_APP_NETWORK_ID === chainId){
localStorage.setItem('currentChain', chainName);
router.replace(
{
query: Object.assign({ ...router.currentRoute.query }, { chain: chainName }),
},
() => {}
);
}
}
window.location.reload();
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/views/Options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,12 @@ export default Vue.extend({
async setCurrentChain() {
localStorage.setItem('currentChain', this.currentChain);
Events.$emit('setting:currentChain', { value: this.currentChain });
(this as any).$router.replace(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a router being used in common.ts without as any conversion. You could create and export a function in common.ts that will do router.replace and call it from here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked it, should work, you can also change (this as any).$router that's in NftDisplay component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kcper @Chriserus Thanks, worked!

{
query: Object.assign({ ...(this as any).$route.query }, { chain: this.currentChain }),
},
() => {}
);
await this.configureMetaMask(+getConfigValue('VUE_APP_NETWORK_ID'));
},
},
Expand Down