-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove storage functions from user session
- Loading branch information
Showing
5 changed files
with
54 additions
and
124 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
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
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,38 @@ | ||
|
||
import { resolveZoneFileToProfile } from './legacy/profiles/profileZoneFiles' | ||
import { fetchPrivate } from '@stacks/common' | ||
import { config } from './legacy/config' | ||
|
||
/** | ||
* Look up a user profile by blockstack ID | ||
* | ||
* @param {string} username - The Blockstack ID of the profile to look up | ||
* @param {string} [zoneFileLookupURL=null] - The URL | ||
* to use for zonefile lookup. If falsey, lookupProfile will use the | ||
* blockstack.js [[getNameInfo]] function. | ||
* @returns {Promise} that resolves to a profile object | ||
*/ | ||
export function lookupProfile(username: string, zoneFileLookupURL?: string): | ||
Promise<Record<string, any>> { | ||
if (!username) { | ||
return Promise.reject() | ||
} | ||
let lookupPromise | ||
if (zoneFileLookupURL) { | ||
const url = `${zoneFileLookupURL.replace(/\/$/, '')}/${username}` | ||
lookupPromise = fetchPrivate(url) | ||
.then(response => response.json()) | ||
} else { | ||
lookupPromise = config.network.getNameInfo(username) | ||
} | ||
return lookupPromise | ||
.then((responseJSON) => { | ||
if (responseJSON.hasOwnProperty('zonefile') | ||
&& responseJSON.hasOwnProperty('address')) { | ||
return resolveZoneFileToProfile(responseJSON.zonefile, responseJSON.address) | ||
} else { | ||
throw new Error('Invalid zonefile lookup response: did not contain `address`' | ||
+ ' or `zonefile` field') | ||
} | ||
}) | ||
} |
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