-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(cat-voices): separating utils in files
- Loading branch information
Showing
4 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
catalyst_voices_packages/catalyst_cardano/catalyst_cardano/wallet-automation/.env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
APP_URL=http://app:80 | ||
WALLET1_SEED_WORD=stomach,horn,rail,afraid,flip,also,abandon,speed,chaos,daring,soon,soft,okay,online,benefit | ||
APP_URL=http://localhost:8000 | ||
WALLET1_SEED_WORD=stomach,horn,rail,afraid,flip,also,abandon,speed,chaos,daring,soon,soft,okay,online,benefit | ||
WALLET1_USERNAME=test123 | ||
WALLET1_PASSWORD=test12345678@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ackages/catalyst_cardano/catalyst_cardano/wallet-automation/utils/extension_downloader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
interface PlatformInfo { | ||
os: string; | ||
arch: string; | ||
nacl_arch: string; | ||
} | ||
|
||
class ExtensionDownloader { | ||
public getCrxUrl(extensionIDOrUrl: string | ExtensionID): string { | ||
let extensionID: string; | ||
|
||
if (typeof extensionIDOrUrl === 'string') { | ||
const idMatch = this.getExtensionID(extensionIDOrUrl); | ||
extensionID = idMatch ? idMatch : extensionIDOrUrl; | ||
} else { | ||
extensionID = extensionIDOrUrl; | ||
} | ||
|
||
if (!/^[a-z]{32}$/.test(extensionID)) { | ||
return extensionIDOrUrl; | ||
} | ||
|
||
const platformInfo = this.getPlatformInfo(); | ||
const productId = this.isChromeNotChromium() ? 'chromecrx' : 'chromiumcrx'; | ||
const productChannel = 'unknown'; | ||
let productVersion = '9999.0.9999.0'; | ||
|
||
const crVersion = /Chrome\/((\d+)\.0\.(\d+)\.\d+)/.exec(navigator.userAgent); | ||
if (crVersion && +crVersion[2] >= 31 && +crVersion[3] >= 1609) { | ||
productVersion = crVersion[1]; | ||
} | ||
|
||
let url = 'https://clients2.google.com/service/update2/crx?response=redirect'; | ||
url += '&os=' + platformInfo.os; | ||
url += '&arch=' + platformInfo.arch; | ||
url += '&os_arch=' + platformInfo.os_arch; | ||
url += '&nacl_arch=' + platformInfo.nacl_arch; | ||
url += '&prod=' + productId; | ||
url += '&prodchannel=' + productChannel; | ||
url += '&prodversion=' + productVersion; | ||
url += '&x=id%3D' + extensionID + '%26installsource%3Dondemand%26uc'; | ||
return url; | ||
} | ||
|
||
private getExtensionID(url: string): string | null { | ||
const pattern = /chrome\.google\.com\/webstore\/detail\/[^\/]+\/([a-z]{32})/i; | ||
const match = pattern.exec(url); | ||
return match ? match[1] : null; | ||
} | ||
|
||
private isChromeNotChromium(): boolean { | ||
return ( | ||
navigator.userAgent.includes('Chrome') && | ||
!navigator.userAgent.includes('Chromium') | ||
); | ||
} | ||
|
||
private getPlatformInfo(): PlatformInfo & { os_arch: string } { | ||
const platform = navigator.platform.toLowerCase(); | ||
let os = 'win'; | ||
if (platform.startsWith('mac')) { | ||
os = 'mac'; | ||
} else if (platform.startsWith('linux')) { | ||
os = 'linux'; | ||
} else if (platform.startsWith('cros')) { | ||
os = 'cros'; | ||
} | ||
|
||
const is64Bit = /x86_64|Win64|WOW64|AMD64/.test(navigator.userAgent); | ||
const arch = is64Bit ? 'x64' : 'x86'; | ||
const os_arch = is64Bit ? 'x86_64' : 'x86'; | ||
const naclArch = is64Bit ? 'x86-64' : 'x86-32'; | ||
|
||
return { os, arch, os_arch, nacl_arch: naclArch }; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...t_voices_packages/catalyst_cardano/catalyst_cardano/wallet-automation/utils/extensions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export interface Extension { | ||
Name: string, | ||
Id: string | ||
} | ||
|
||
export enum ExtensionName { | ||
Lace = 'Lace', | ||
Typhon = 'Typhon' | ||
} | ||
|
||
const extensions: Extension[] = [ | ||
{ | ||
Name: ExtensionName.Lace, | ||
Id: 'lace-id' | ||
}, | ||
{ | ||
Name: ExtensionName.Typhon, | ||
Id: 'typhon-id' | ||
} | ||
]; |