Skip to content

Commit

Permalink
resolves #1031
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinunger committed Jan 19, 2022
1 parent 901cc68 commit 83dbbcb
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
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(
{
query: Object.assign({ ...(this as any).$route.query }, { chain: this.currentChain }),
},
() => {}
);
await this.configureMetaMask(+getConfigValue('VUE_APP_NETWORK_ID'));
},
},
Expand Down

0 comments on commit 83dbbcb

Please sign in to comment.