diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6e6fb2c..9666444 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- "Copy details" button on each route card — copies the route path, fee,
and time as plain text to the clipboard (resolves #21).
+- Loading state while routes are being calculated: short artificial delay
+ plus spinner, stylable ahead of Phase 2's real network calls (resolves #16).
- Unit test for `availableCurrencies()` (resolves #27).
- Component tests for `RouteList` covering the not-searched, empty, and
populated states (resolves #25).
diff --git a/src/App.jsx b/src/App.jsx
index c750245..092a9b5 100644
--- a/src/App.jsx
+++ b/src/App.jsx
@@ -13,19 +13,25 @@ export default function App() {
const [searched, setSearched] = useState(false)
const [lastQuery, setLastQuery] = useState(null)
const [engineError, setEngineError] = useState(null)
+ const [loading, setLoading] = useState(false)
const currencies = availableCurrencies()
- function handleSubmit({ fromCurrency, toCurrency, amount }) {
+ async function handleSubmit({ fromCurrency, toCurrency, amount }) {
+ if (loading) return
setEngineError(null)
+ setSearched(false)
+ setLoading(true)
try {
+ await new Promise((resolve) => setTimeout(resolve, 500))
const found = findRoutesCached({ fromCurrency, toCurrency, amount, anchors: mockAnchors })
setRoutes(found)
setLastQuery({ fromCurrency, toCurrency, amount })
setSearched(true)
} catch (err) {
setEngineError(err.message)
- setSearched(false)
+ } finally {
+ setLoading(false)
}
}
@@ -51,7 +57,14 @@ export default function App() {
)}
-
+ {loading ? (
+
+
+ Finding routes…
+
+ ) : (
+
+ )}