Skip to content

Commit

Permalink
Merge pull request #1040 from CryptoBlades/issue-1031
Browse files Browse the repository at this point in the history
chain is now in url as param
  • Loading branch information
kevinunger committed Jan 19, 2022
2 parents 79fb6f3 + 0679724 commit f542d2a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
25 changes: 25 additions & 0 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ import { apiUrl } from './utils/common';
import i18n from './i18n';
import { getConfigValue } from './contracts';
import '@/mixins/general';
import config from '../app-config.json';
import { addChainToRouter } from '@/utils/common';
Vue.directive('visible', (el, bind) => {
el.style.visibility = bind.value ? 'visible' : 'hidden';
Expand Down Expand Up @@ -139,6 +141,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 +169,28 @@ 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){
localStorage.setItem('currentChain', currentChain);
addChainToRouter(currentChain);
}
//add chain as query param if chain unchanged
if(currentChain === paramChain || !paramChain){
localStorage.setItem('currentChain', currentChain);
addChainToRouter(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'));
}
},
async updateCharacterStamina(id) {
if (this.featureFlagStakeOnly) return;
Expand Down Expand Up @@ -312,6 +336,7 @@ export default {
},
async created() {
this.checkChainAndParams();
try {
await this.initializeStore();
} catch (e) {
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ 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 });

const web3 = new Web3(Web3.givenProvider || process.env.VUE_APP_WEB3_FALLBACK_PROVIDER);

export function addChainToRouter(chain: string){
router.replace(
{
query: Object.assign({ ...router.currentRoute.query }, { chain }),
},
() => {}
);
}

interface Config {
environments: Record<string, Chain>;
}
Expand All @@ -25,6 +36,7 @@ interface Chain {
for (const [chainName, values] of Object.entries(chains)){
if(+values.VUE_APP_NETWORK_ID === chainId){
localStorage.setItem('currentChain', chainName);
addChainToRouter(chainName);
}
}
window.location.reload();
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/views/Options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import i18n from '../i18n';
import { getConfigValue } from '@/contracts';
import config from '../../app-config.json';
import { SupportedProject } from './Treasury.vue';
import { addChainToRouter } from '@/utils/common';
interface StoreMappedState {
skillRewards: string;
Expand Down Expand Up @@ -302,6 +303,7 @@ export default Vue.extend({
async setCurrentChain() {
localStorage.setItem('currentChain', this.currentChain);
Events.$emit('setting:currentChain', { value: this.currentChain });
addChainToRouter(this.currentChain);
await this.configureMetaMask(+getConfigValue('VUE_APP_NETWORK_ID'));
},
},
Expand Down

0 comments on commit f542d2a

Please sign in to comment.