-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hook to fetch delegation outputs
- Loading branch information
Showing
7 changed files
with
135 additions
and
2 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
43 changes: 43 additions & 0 deletions
43
client/src/helpers/nova/hooks/useAddressDelegationOutputs.ts
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,43 @@ | ||
import { OutputResponse } from "@iota/sdk-wasm-nova/web"; | ||
import { useEffect, useState } from "react"; | ||
import { useIsMounted } from "~helpers/hooks/useIsMounted"; | ||
import { ServiceFactory } from "~factories/serviceFactory"; | ||
import { NOVA } from "~models/config/protocolVersion"; | ||
import { NovaApiClient } from "~/services/nova/novaApiClient"; | ||
|
||
/** | ||
* Fetch Address delegation UTXOs | ||
* @param network The Network in context | ||
* @param addressBech32 The address in bech32 format | ||
* @returns The output responses and loading bool. | ||
*/ | ||
export function useAddressDelegationOutputs(network: string, addressBech32: string | null): [OutputResponse[] | null, boolean] { | ||
const isMounted = useIsMounted(); | ||
const [apiClient] = useState(ServiceFactory.get<NovaApiClient>(`api-client-${NOVA}`)); | ||
const [outputs, setOutputs] = useState<OutputResponse[] | null>(null); | ||
const [isLoading, setIsLoading] = useState<boolean>(true); | ||
|
||
useEffect(() => { | ||
setIsLoading(true); | ||
setOutputs(null); | ||
if (addressBech32) { | ||
// eslint-disable-next-line no-void | ||
void (async () => { | ||
apiClient | ||
.delegationOutputsDetails({ network, address: addressBech32 }) | ||
.then((response) => { | ||
if (!response?.error && response.outputs && isMounted) { | ||
setOutputs(response.outputs); | ||
} | ||
}) | ||
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
})(); | ||
} else { | ||
setIsLoading(false); | ||
} | ||
}, [network, addressBech32]); | ||
|
||
return [outputs, isLoading]; | ||
} |
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
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