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 all commits
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
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 @@ -101,6 +101,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 @@ -303,6 +304,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