@roochnetwork/rooch-sdk-kit
Version:
Rooch SDK Kit
67 lines (63 loc) • 2.03 kB
JavaScript
// src/components/ProgressProvider.tsx
import { createContext, useCallback, useContext, useState } from "react";
// src/components/fauct-modal/views/FaucetView.css.ts
var progressBar = "FaucetView_progressBar__1ff62y03";
// src/components/ui/Progress.tsx
import { jsx } from "react/jsx-runtime";
function Progress() {
const { progress } = useProgress();
return /* @__PURE__ */ jsx("div", { className: progressBar, style: { width: `${progress}%` } });
}
// src/components/ProgressProvider.tsx
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
var ProgressProviderContext = createContext(null);
var ProgressProvider = ({ children }) => {
const [progress, setProgress] = useState(0);
const [loading, setLoading] = useState(false);
const start = useCallback(() => {
setLoading(true);
setProgress(0);
const interval = setInterval(() => {
setProgress((prev) => {
const nextProgress = prev + 10;
if (nextProgress >= 70) {
clearInterval(interval);
}
return Math.min(nextProgress, 70);
});
}, 100);
}, []);
const finish = useCallback((callback) => {
const interval = setInterval(() => {
setProgress((prev) => {
const nextProgress = prev + 5;
if (nextProgress >= 100) {
clearInterval(interval);
setTimeout(() => {
setLoading(false);
if (callback) {
callback();
}
}, 300);
}
return Math.min(nextProgress, 100);
});
}, 50);
}, []);
return /* @__PURE__ */ jsxs(ProgressProviderContext.Provider, { value: { loading, progress, start, finish }, children: [
children,
loading && /* @__PURE__ */ jsx2(Progress, {})
] });
};
var useProgress = () => {
const ctx = useContext(ProgressProviderContext);
if (!ctx) {
throw new Error("useSubscribeToError must be used within a GlobalProvider");
}
return ctx;
};
export {
ProgressProvider,
useProgress
};
//# sourceMappingURL=ProgressProvider.js.map