mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-04-26 23:57:59 +00:00
Set location.hash to current chain (#63)
This commit is contained in:
@@ -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)}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user