-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from cosmos/chore/custom-request
Remove axios and use custom fetch wrapper
- Loading branch information
Showing
16 changed files
with
1,137 additions
and
8,659 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
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,31 @@ | ||
import { useEffect, useState } from "react"; | ||
import { RequestConfig, requestJson } from "../lib/request"; | ||
|
||
type Status = | ||
| { readonly stage: "idle" | "loading"; readonly data?: never; readonly error?: never } | ||
| { readonly stage: "resolved"; readonly data: unknown; readonly error?: never } | ||
| { readonly stage: "rejected"; readonly data?: never; readonly error: string }; | ||
|
||
export default function useRequestJson(endpoint: string, config: RequestConfig = {}) { | ||
const [status, setStatus] = useState<Status>({ stage: "idle" }); | ||
const { stage, data, error } = status; | ||
|
||
useEffect(() => { | ||
(async function () { | ||
if (stage === "idle") { | ||
setStatus({ stage: "loading" }); | ||
} | ||
|
||
if (stage === "loading") { | ||
try { | ||
const newData = await requestJson(endpoint, config); | ||
setStatus({ stage: "resolved", data: newData }); | ||
} catch (e) { | ||
setStatus({ stage: "rejected", error: e instanceof Error ? e.message : String(e) }); | ||
} | ||
} | ||
})(); | ||
}, [config, endpoint, stage]); | ||
|
||
return { loading: stage === "idle" || stage === "loading", data, error }; | ||
} |
Oops, something went wrong.
43ebe91
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
cosmos-multisig-ui – ./
cosmos-multisig-ui-interchain.vercel.app
cosmos-multisig-ui-kohl.vercel.app
cosmos-multisig-ui-git-master-interchain.vercel.app