forked from dcSpark/adalib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
689 additions
and
252 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -6,3 +6,5 @@ export { | |
sendTransaction, | ||
watchTransaction, | ||
} from "./transactions"; | ||
|
||
export { fetchName } from "./nameService"; |
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,40 @@ | ||
import { Connection, PublicKey } from "@solana/web3.js"; | ||
import { solanaClusters } from "../defaults/clusters"; | ||
import { getFavoriteDomain, getAllDomains, performReverseLookup } from "./spl"; | ||
|
||
export type FetchNameArgs = { | ||
address: string | ||
} | ||
|
||
export type FetchNameResult = string | null | ||
|
||
/** | ||
* Retrieves a domain name to display for a user if any | ||
* First it attempts to get the favorite domain. | ||
* This feature doesn't appear to commonly be used hence | ||
* if none is set we try to capture other domains associated to the | ||
* account and use the first one that pops up. | ||
* @param connection The Solana RPC connection object | ||
* @param owner The owner you want to retrieve the favorite domain for | ||
* @returns | ||
*/ | ||
export async function fetchName(args: FetchNameArgs): Promise<FetchNameResult> { | ||
const connection = new Connection(solanaClusters.mainnetBeta.endpoint, 'confirmed'); | ||
const address = new PublicKey(args.address); | ||
|
||
try { | ||
return (await getFavoriteDomain(connection, address)).reverse; | ||
} catch (e) {} | ||
|
||
const otherDomains = await getSolDomainsFromPublicKey(connection, address); | ||
|
||
return otherDomains.length > 0 ? otherDomains[0] : null; | ||
} | ||
|
||
async function getSolDomainsFromPublicKey(connection: Connection, wallet: PublicKey):Promise<string[]>{ | ||
const allDomainKeys = await getAllDomains(connection, wallet); | ||
const allDomainNames = await Promise.all(allDomainKeys.map((key: PublicKey) => { | ||
return performReverseLookup(connection, key) | ||
})); | ||
return allDomainNames; | ||
} |
Oops, something went wrong.