mirror of
https://github.com/luxfi/wc-core.git
synced 2026-10-30 15:12:42 +00:00
31 lines
994 B
JavaScript
31 lines
994 B
JavaScript
const domain = "walletconnect.org";
|
|
const alphanumerical = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
const bridges = alphanumerical.split("").map(char => `https://${char}.bridge.walletconnect.org`);
|
|
export function extractHostname(url) {
|
|
let hostname = url.indexOf("//") > -1 ? url.split("/")[2] : url.split("/")[0];
|
|
hostname = hostname.split(":")[0];
|
|
hostname = hostname.split("?")[0];
|
|
return hostname;
|
|
}
|
|
export function extractRootDomain(url) {
|
|
return extractHostname(url)
|
|
.split(".")
|
|
.slice(-2)
|
|
.join(".");
|
|
}
|
|
export function randomBridgeIndex() {
|
|
return Math.floor(Math.random() * bridges.length);
|
|
}
|
|
export function selectRandomBridgeUrl() {
|
|
return bridges[randomBridgeIndex()];
|
|
}
|
|
export function shouldSelectRandomly(url) {
|
|
return extractRootDomain(url) === domain;
|
|
}
|
|
export function getBridgeUrl(url) {
|
|
if (shouldSelectRandomly(url)) {
|
|
return selectRandomBridgeUrl();
|
|
}
|
|
return url;
|
|
}
|
|
//# sourceMappingURL=url.js.map
|