generated from visoftsolutions/ksox-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exchange layout and market middleware
- Loading branch information
Bartosz Nowak
committed
Oct 22, 2023
1 parent
baa5209
commit 202632b
Showing
6 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,28 @@ | ||
import { component$ } from "@builder.io/qwik"; | ||
import { type RequestHandler, routeLoader$ } from "@builder.io/qwik-city"; | ||
import { parseMarket } from "./parseMarket"; | ||
|
||
export const onRequest: RequestHandler = ({ params, redirect, sharedMap }) => { | ||
try { | ||
const market = parseMarket(params.market); | ||
sharedMap.set("quoteAsset", market.quoteAsset); | ||
sharedMap.set("baseAsset", market.baseAsset); | ||
} catch (error) { | ||
redirect(300, "/"); | ||
} | ||
}; | ||
|
||
export const useMarket = routeLoader$(({ sharedMap }) => { | ||
return { | ||
quoteAsset: sharedMap.get("quoteAsset") as string, | ||
baseAsset: sharedMap.get("baseAsset") as string, | ||
}; | ||
}); | ||
|
||
export default component$(() => { | ||
const { quoteAsset, baseAsset } = useMarket().value; | ||
console.log(quoteAsset); | ||
console.log(baseAsset); | ||
|
||
return <></>; | ||
}); |
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,12 @@ | ||
export const parseMarket = (market: string) => { | ||
const regex = /^(\w+)-(\w+)$/; | ||
const match = market.match(regex); | ||
if (match) { | ||
return { | ||
quoteAsset: match[1].toUpperCase(), | ||
baseAsset: match[2].toUpperCase(), | ||
}; | ||
} else { | ||
throw new Error("Cound not parse market"); | ||
} | ||
}; |
Empty file.
Empty file.
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,9 @@ | ||
import { component$, Slot } from "@builder.io/qwik"; | ||
|
||
export default component$(() => { | ||
return ( | ||
<> | ||
<Slot /> | ||
</> | ||
); | ||
}); |