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

feat: we have a single vault link for all platforms #94

Merged
merged 1 commit into from
Jun 4, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed libs/iota-browser/affinidi-tdk-iota-client-1.0.0.tgz
Binary file not shown.
22 changes: 11 additions & 11 deletions libs/iota-browser/src/helpers/vault-handler.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { WindowCache } from "./window-cache";
import { WindowCache } from './window-cache'

export class VaultHandler {
private cache = new WindowCache();
private cache = new WindowCache()

public openVault(id: string, link: string, window: Window) {
const win = window.open(link); // open - opens in a new window
this.cache.addWindow(id, win);
}
public openVault(id: string, link: string, window: Window) {
const win = window.open(link) // open - opens in a new window
this.cache.addWindow(id, win)
}

public closeVault(id: string) {
const win = this.cache.getWindow(id);
if (win) win.close();
this.cache.deleteWindow(id);
}
public closeVault(id: string) {
const win = this.cache.getWindow(id)
if (win) win.close()
this.cache.deleteWindow(id)
}
}
22 changes: 11 additions & 11 deletions libs/iota-browser/src/helpers/window-cache.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export class WindowCache {
private cache: { [key: string]: any } = {}
private cache: { [key: string]: any } = {}

public addWindow(id: string, window: any) {
this.cache[id] = window;
}
public getWindow(id: string): any {
return this.cache[id];
}
public deleteWindow(id: string) {
return delete this.cache[id];
}
}
public addWindow(id: string, window: any) {
this.cache[id] = window
}
public getWindow(id: string): any {
return this.cache[id]
}
public deleteWindow(id: string) {
return delete this.cache[id]
}
}
32 changes: 9 additions & 23 deletions packages/iota-utils/iota-utils.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,20 @@
import { EnvironmentHandler } from './helpers'
import { Environment } from './helpers/environment'

export interface IAffinidiVaultLinks {
web: string
android: string
ios: string
}

const LOCAL_WEB_VAULT_URL = 'http://localhost:3001/login'
const DEV_WEB_VAULT_URL = 'https://vault.dev.affinidi.com/login'
const PROD_WEB_VAULT_URL = 'https://vault.affinidi.com/login'
const LOCAL_VAULT_URL = 'http://localhost:3001/login'
const DEV_VAULT_URL = 'https://vault.dev.affinidi.com/login'
const PROD_VAULT_URL = 'https://vault.affinidi.com/login'

const envToWebVaultUrlMap = {
[Environment.LOCAL]: LOCAL_WEB_VAULT_URL,
[Environment.DEVELOPMENT]: DEV_WEB_VAULT_URL,
[Environment.PRODUCTION]: PROD_WEB_VAULT_URL,
[Environment.LOCAL]: LOCAL_VAULT_URL,
[Environment.DEVELOPMENT]: DEV_VAULT_URL,
[Environment.PRODUCTION]: PROD_VAULT_URL,
}

const ANDROID_VAULT_URL = 'affinidi-vault//something'
const IOS_VAULT_URL = 'affinidi-vault//something'

export class IotaUtils {
static env = new EnvironmentHandler().fetchEnvironment()

static createVaultLinks(request: {
[key: string]: any
}): IAffinidiVaultLinks {
static createVaultLink(request: { [key: string]: any }): string {
if (!request.payload.request || !request.payload.client_id) {
throw Error('Please provide request and client_id in payload')
}
Expand All @@ -34,11 +23,8 @@ export class IotaUtils {
params.append('client_id', request.payload.client_id)

const queryString = params.toString()
const vaultLink = `${envToWebVaultUrlMap[this.env] || PROD_VAULT_URL}?${queryString}`

return {
web: `${envToWebVaultUrlMap[this.env] || PROD_WEB_VAULT_URL}?${queryString}`,
android: `${ANDROID_VAULT_URL}?${queryString}`,
ios: `${IOS_VAULT_URL}?${queryString}`,
}
return vaultLink
}
}
Loading