lumina/ui/util/federation-hooks.js
2025-11-29 23:13:05 +03:00

22 lines
812 B
JavaScript

import {Federation} from '@stellar/stellar-sdk'
import {useDependantState} from '@stellar-expert/ui-framework'
/**
* Resolve federation address for account through federation server specified in stellar.toml
* @param {String} account
* @param {Boolean} [skipFederationErrors]
* @returns {String}
*/
export function useResolvedFederationName(account, skipFederationErrors = true) {
const [federationName, setFederationName] = useDependantState(() => {
Federation.Server.resolve(account)
.then(res => setFederationName(res.stellar_address || null))
.catch(e => {
if (skipFederationErrors)
return //ignore federation errors
console.error(e)
})
return null
}, [account])
return federationName
}