-
Notifications
You must be signed in to change notification settings - Fork 5
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
BNS domains that resolve to addresses now searchable #57
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ import { OnlineRepsService } from '@app/services/online-reps/online-reps.service | |
import { NavigationEnd, Router } from '@angular/router'; | ||
import { Subscription } from 'rxjs'; | ||
import { AliasService } from '@app/services/alias/alias.service'; | ||
import { APP_NAV_ITEMS, hashNavItem } from '../../navigation/nav-items'; | ||
import { APP_NAV_ITEMS, accountNavItem, hashNavItem } from '../../navigation/nav-items'; | ||
import { environment } from '../../../environments/environment'; | ||
import { DelegatorsTabService } from '@app/pages/account/tabs/delegators/delegators-tab.service'; | ||
import { InsightsTabService } from '@app/pages/account/tabs/insights/insights-tab.service'; | ||
|
@@ -64,12 +64,12 @@ export class AccountComponent implements OnDestroy { | |
private readonly _insightsTabService: InsightsTabService, | ||
private readonly _delegatorsTabService: DelegatorsTabService | ||
) { | ||
this.routeListener = this._router.events.subscribe((route) => { | ||
this.routeListener = this._router.events.subscribe(async (route) => { | ||
if (route instanceof NavigationEnd) { | ||
const splitUrl = this._router.url.replace('/history', '').split('/'); | ||
const path = splitUrl[splitUrl.length - 1]; | ||
const address = path.substring(0, 64); | ||
this._searchAccount(address); | ||
await this._searchAccount(address); | ||
} | ||
}); | ||
|
||
|
@@ -111,13 +111,28 @@ export class AccountComponent implements OnDestroy { | |
void this._router.navigate([`/${hashNavItem.route}/${hash}`], { replaceUrl: true }); | ||
} | ||
|
||
/** Call this method whenever someone has enters a BNS domain, and it is resolved to a Banano address. */ | ||
private _redirectToAccountPage(account: string): void { | ||
void this._router.navigate([`/${accountNavItem.route}/${account}`], { replaceUrl: true }); | ||
} | ||
|
||
/** Given a ban address, searches for account. */ | ||
private _searchAccount(address): void { | ||
private async _searchAccount(address): Promise<void> { | ||
if (!address) { | ||
return; | ||
} | ||
|
||
if (!address.startsWith('ban_')) { | ||
const parts = address.split('.'); | ||
if (parts.length === 2) { | ||
//search in api | ||
try { | ||
const domain = await this.apiService.fetchBNSDomain(parts[0], parts[1]); | ||
if (domain.domain?.resolved_address) { | ||
return this._redirectToAccountPage(domain.domain?.resolved_address); | ||
} | ||
} catch (_) {} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we get a quick comment here explaining what this does? If not a ban address, assume it's BNS? |
||
this._redirectToHashPage(address); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -204,6 +204,17 @@ export class ApiService { | |
.toPromise(); | ||
} | ||
|
||
/** Fetch/query BNS domain. */ | ||
async fetchBNSDomain(domain_name: string, tld: string): Promise<any> { | ||
await this._hasPingedApi(); | ||
return this._http | ||
.post<any>(`${this.httpApi}/v1/account/bns`, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we get some stronger typings here? The api is versioned so we should know what schema to expect. Specifically looking to remove the |
||
domain_name, | ||
tld, | ||
}) | ||
.toPromise(); | ||
} | ||
|
||
/** Fetches monitored representatives stats. */ | ||
async fetchMonitoredRepresentatives(): Promise<MonitoredRepDto[]> { | ||
await this._hasPingedApi(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,14 +12,14 @@ export class SearchService { | |
constructor(router: Router) { | ||
this.searchEvents().subscribe((data: { search: string; openInNewWindow: boolean }) => { | ||
if (data.openInNewWindow) { | ||
if (data.search.startsWith('ban_')) { | ||
if (data.search.startsWith('ban_') || this.isValidBNSDomain(data.search)) { | ||
const origin = window.location.origin; | ||
window.open(`${origin}/${APP_NAV_ITEMS.account.route}/${data.search}`, '_blank'); | ||
} else { | ||
window.open(`${origin}/${APP_NAV_ITEMS.hash.route}/${data.search}`, '_blank'); | ||
} | ||
} else { | ||
if (data.search.startsWith('ban_')) { | ||
if (data.search.startsWith('ban_') || this.isValidBNSDomain(data.search)) { | ||
void router.navigate([`${APP_NAV_ITEMS.account.route}/${data.search}`]); | ||
} else { | ||
void router.navigate([`${APP_NAV_ITEMS.hash.route}/${data.search}`]); | ||
|
@@ -47,4 +47,10 @@ export class SearchService { | |
isValidBlock(block: string): boolean { | ||
return block && block.length === 64; | ||
} | ||
|
||
isValidBNSDomain(bns: string): boolean { | ||
const parts = bns.split('.'); | ||
//later, can also check for illegal characters once that is more settled | ||
return parts.length === 2 && parts[0].length <= 32; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be placed in the UtilService & then used here & in the AccountComponent? |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
isValidBNSDomain
utility function here?