Skip to content

Commit 8bda8a7

Browse files
authored
feat(sdk-react-provider): complete refactor to use react-query async state management
* feat: update sdk-react-provider to use react-query * fix: merge providers and add docs * fix: tests * fix: more tests * feat: add useProfiles and useOrder + tests * fix: invalidate the correct query on linkAddress * fix: update docs * fix: update docs * fix: add api example * fix: update docs * fix: merge get balances and get profile balances * fix: cleanup * feat: placeOrderMessage, rearranged args, currency required, chainId number or moneriumChainName * fix: set monerium identifier for cache keys so it wont clash with wagmi or other * fix: authorization, offer auto link and revoking access * fix: added landing page that tests most aspects of the hooks * fix: remove deprecated functions and network * fix: update lockfile * test: update placeOrderMessage test * docs: update generated docs * fix: tests, currency is now required in placeOrder * fix: comment out api example dependecies * fix: react hooks tests * fix: remove duplicated getAuthFlowURI * fix: disable test, it fails when its run with turbo * docs: update documentation
1 parent 03e373c commit 8bda8a7

File tree

139 files changed

+7099
-4645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+7099
-4645
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The pipeline will automatically publish the following packages if there are chan
6565

6666
#### Useful links
6767

68-
[Release please - Github action](https://github.com/marketplace/actions/release-please-action)
68+
[Release please - Github action](https://github.com/marketplace/actions/release-please-action)</br>
6969
[Release please - Config file options](https://github.com/googleapis/release-please/blob/main/docs/manifest-releaser.md#configfile)
7070

7171
### Remote Caching

apps/customer/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update
2020

2121
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load Inter, a custom Google Font.
2222

23+
## Useful
24+
25+
https://vercel.com/blog/common-mistakes-with-the-next-js-app-router-and-how-to-fix-them
26+
2327
## Learn More
2428

2529
To learn more about Next.js, take a look at the following resources:

apps/customer/app/(authorized)/dashboard/page.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
'use client';
22

3-
import { useState } from 'react';
3+
import { useEffect, useState } from 'react';
44
import Box from '@mui/material/Box';
55
import Stack from '@mui/material/Stack';
66

77
import { Currency } from '@monerium/sdk';
8+
import { useBalances } from '@monerium/sdk-react-provider';
89

910
import ChainFilter from 'components/Dashboard/Filters/ChainFilter';
1011
import TokenFilter from 'components/Dashboard/Filters/TokenFilter';
1112
import TotalBalance from 'components/Dashboard/TotalBalance';
1213
import { ChainSelection } from 'components/Dashboard/types';
1314
import WalletList from 'components/Dashboard/WalletList';
14-
// import { ConnectButton } from '@rainbow-me/rainbowkit';
1515

1616
function Dashboard() {
1717
const [selectedChain, setSelectedChain] = useState<ChainSelection>('all');
@@ -20,6 +20,16 @@ function Dashboard() {
2020
Currency.eur
2121
);
2222

23+
const { refetch } = useBalances({
24+
query: {
25+
refetchOnWindowFocus: false,
26+
},
27+
});
28+
29+
useEffect(() => {
30+
refetch();
31+
}, [selectedCurrency, selectedChain]);
32+
2333
return (
2434
<Box sx={{ pt: 7 }}>
2535
<Stack direction="row" sx={{ p: 3 }}>

apps/customer/app/(authorized)/layout.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useRouter } from 'next/navigation';
33
import Box from '@mui/material/Box';
44
import Paper from '@mui/material/Paper';
55

6-
import { useMonerium } from '@monerium/sdk-react-provider';
6+
import { useAuth } from '@monerium/sdk-react-provider';
77

88
import { LoadingScreen } from 'components/LoadingScreen';
99
import BottomNavigation from 'components/Navigation/BottomNavigation';
@@ -13,14 +13,14 @@ export default function AuthorizedLayout({
1313
}: Readonly<{
1414
children: React.ReactNode;
1515
}>) {
16-
const { isAuthorized, loadingAuth } = useMonerium();
16+
const { isAuthorized, isLoading } = useAuth();
1717
const router = useRouter();
1818

19-
if (loadingAuth) {
19+
if (isLoading) {
2020
return <LoadingScreen />;
2121
}
2222

23-
if (!loadingAuth && !isAuthorized) {
23+
if (!isLoading && !isAuthorized) {
2424
router.push('/');
2525
}
2626

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// import { cookies } from 'next/headers';
2+
import { NextRequest, NextResponse } from 'next/server';
3+
// import cookie from 'cookie';´
4+
5+
export async function POST(req: NextRequest) {
6+
const requestBody = await req.json();
7+
8+
let response;
9+
try {
10+
response = await fetch(`https://example.com`, {
11+
method: 'POST',
12+
headers: {
13+
'Content-Type': 'application/json',
14+
},
15+
body: JSON.stringify(requestBody),
16+
}).then((res) => res.json());
17+
18+
if (response.code) {
19+
return new NextResponse(JSON.stringify(response), {
20+
status: response.code,
21+
headers: {
22+
'Content-Type': 'application/json',
23+
},
24+
});
25+
}
26+
27+
// const { 'session-id': sessionId, ...cookieOptions } = cookie.parse(
28+
// response.headers.get('set-cookie')
29+
// );
30+
// cookies().set('session-id', sessionId, cookieOptions);
31+
32+
return new NextResponse(JSON.stringify(response), {
33+
status: 200,
34+
headers: {
35+
'Content-Type': 'application/json',
36+
},
37+
});
38+
} catch (error) {
39+
return new NextResponse(
40+
JSON.stringify({ message: (error as Error).message }),
41+
{
42+
status: 500,
43+
headers: {
44+
'Content-Type': 'application/json',
45+
},
46+
}
47+
);
48+
}
49+
}
50+
51+
export async function GET(req: NextRequest) {
52+
return Response.json({ data: 'example' });
53+
}

apps/customer/app/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import Box from '@mui/material/Box';
66
import Container from '@mui/material/Container';
77
import Typography from '@mui/material/Typography';
88

9-
import { useMonerium } from '@monerium/sdk-react-provider';
9+
import { useAuth } from '@monerium/sdk-react-provider';
1010

1111
import { MoneriumConnect } from 'components/MoneriumConnect/MoneriumConnect';
1212
import { LoadingScreen } from 'src/components/LoadingScreen';
1313

1414
import s from './page.module.scss';
1515

1616
export default function Home() {
17-
const { isAuthorized, loadingAuth } = useMonerium();
17+
const { isAuthorized, isLoading } = useAuth();
1818
const router = useRouter();
1919

2020
useEffect(() => {
@@ -23,7 +23,7 @@ export default function Home() {
2323
}
2424
}, [isAuthorized]);
2525

26-
if (!loadingAuth && !isAuthorized) {
26+
if (!isLoading && !isAuthorized) {
2727
return (
2828
<Container component="main" maxWidth="md">
2929
<Box className={s.logoWrapper}>

0 commit comments

Comments
 (0)