Skip to content

Commit

Permalink
feat: return error to useConfluxPortal hook (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
zctocm authored Jun 7, 2021
1 parent e1f8894 commit c935b4c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/useConfluxPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default function useConfluxPortal(tokenAddrs = []) {
: null
);
const [chainId, setChainId] = useState(window?.conflux?.chainId);
const [error,setError]=useState(null)

useEffectOnce(() => {
window?.conflux?.send({ method: "cfx_accounts" }).then((accounts) => {
Expand All @@ -60,12 +61,15 @@ export default function useConfluxPortal(tokenAddrs = []) {

const login = (fallbackFn) => {
if (!address) {
if (window?.conflux?.enable)
if (window?.conflux)
return window.conflux
.enable()
.send('cfx_requestAccounts')
.then(
(addresses) => validAddresses(addresses) && setAddress(addresses[0])
);
)
.catch(
(error)=>setError(error)
)
return typeof fallbackFn === "function" && fallbackFn();
}
};
Expand Down Expand Up @@ -107,6 +111,7 @@ export default function useConfluxPortal(tokenAddrs = []) {
address,
balances: [balance, tokenBalances],
chainId,
error,
login,
useEnsurePortalLogin,
conflux: window?.conflux,
Expand Down

0 comments on commit c935b4c

Please sign in to comment.