Set location.hash to current chain (#63)

This commit is contained in:
Maciej Hirsz
2018-09-27 22:26:47 +02:00
committed by GitHub
parent c4bfc47c8a
commit 250e0db51e
4 changed files with 40 additions and 13 deletions
+26
View File
@@ -57,3 +57,29 @@ export function secondsWithPrecision(num: number): string {
default: return intString + 's';
}
}
export interface HashData {
tab?: string;
chain?: Types.ChainLabel;
};
export function getHashData(): HashData {
const { hash } = window.location;
if (hash[0] !== '#') {
return {};
}
const [tab, rawChain] = hash.substr(1).split('/');
const chain = decodeURIComponent(rawChain) as Types.ChainLabel;
return { tab, chain };
}
export function setHashData(val: HashData) {
const update = Object.assign(getHashData(), val);
const { tab = '', chain = '' } = update;
window.location.hash = `#${tab}/${encodeURIComponent(chain)}`;
}