-
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.
* use names from people chain * make it prerenderable * longer names
- Loading branch information
Showing
8 changed files
with
84 additions
and
17 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
Binary file not shown.
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,10 +1,14 @@ | ||
{ | ||
"version": 0, | ||
"descriptorPath": ".papi/descriptors", | ||
"entries": { | ||
"dot": { | ||
"chain": "polkadot", | ||
"metadata": ".papi/metadata/dot.scale" | ||
} | ||
} | ||
} | ||
"version": 0, | ||
"descriptorPath": ".papi/descriptors", | ||
"entries": { | ||
"dot": { | ||
"chain": "polkadot", | ||
"metadata": ".papi/metadata/dot.scale" | ||
}, | ||
"people": { | ||
"chain": "polkadot_people", | ||
"metadata": ".papi/metadata/people.scale" | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,50 @@ | ||
import { get, writable } from 'svelte/store'; | ||
import { withPolkadotSdkCompat } from 'polkadot-api/polkadot-sdk-compat'; | ||
import { type Binary, createClient } from 'polkadot-api'; | ||
import { people } from '@polkadot-api/descriptors'; | ||
import { WsEvent } from '@polkadot-api/ws-provider/web'; | ||
import { getWsProvider } from 'polkadot-api/ws-provider/web'; | ||
|
||
const endpoints = [ | ||
'wss://polkadot-people-rpc.polkadot.io', | ||
'wss://sys.ibp.network/people-polkadot', | ||
'wss://people-polkadot.dotters.network', | ||
'wss://rpc-people-polkadot.luckyfriday.io', | ||
'wss://people-polkadot.public.curie.radiumblock.co' | ||
]; | ||
|
||
function createPeopleTypedApi() { | ||
const sdkProvider = withPolkadotSdkCompat( | ||
getWsProvider({ | ||
endpoints, | ||
timeout: 5000, | ||
onStatusChanged(event) { | ||
if (event.type !== WsEvent.CONNECTED) return; | ||
console.log(`Connected People to ${event.uri}`); | ||
} | ||
}) | ||
); | ||
const sdkClient = createClient(sdkProvider); | ||
return sdkClient.getTypedApi(people); | ||
} | ||
|
||
const peopleApi = writable<undefined | ReturnType<typeof createPeopleTypedApi>>(); | ||
|
||
export async function getPeopleChainName(address: string | undefined) { | ||
if (!address) return; | ||
|
||
if (!get(peopleApi)) { | ||
peopleApi.set(createPeopleTypedApi()); | ||
} | ||
const api = get(peopleApi); | ||
if (!api) return; | ||
|
||
const result = await api.query.Identity.IdentityOf.getValue(address); | ||
if (!result) return; | ||
|
||
const value = result[0].info.display.value as Binary | undefined; | ||
const text = value?.asText(); | ||
if (!text) return; | ||
|
||
return `✅ ${text.substring(0, 20)}`; | ||
} |