Skip to content

Commit 5f9c5c9

Browse files
committed
[RSO] Start retrieving recent matches
Began implementation of how to fetch to Riot endpoint to retrieve array of recent match ids of a player that logged in via RSO.
1 parent 774ade9 commit 5f9c5c9

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/web/src/App.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,12 @@ function App() {
157157
axios.get(`/rso/getUserInfo/${RSOAccessToken}`).then((res) => {
158158
setGameName(res.data.gameName);
159159
setTagLine(res.data.tagLine);
160-
console.log("App.tsx ran getUserInfo correctly");
161-
console.log("We set gameName to: ", gameName);
162-
console.log("We set tagLine to: ", tagLine);
160+
// Making this postBody object instead of directly passing into axios.post as second arg works
161+
const postBody = {gameName: res.data.gameName, tagLine: res.data.tagLine};
162+
axios.post('/rso/getPuuid', postBody).then((resp) => {
163+
setPuuid(resp.data.puuid);
164+
}).catch((error) => {return error; })
163165
}).catch((error) => { return error; }) // .get.then.catch avoids async and await
164-
165-
// 400 bad request by below code, but endpoint def works on postman?
166-
// Since the puuid from above isn't decryptable
167-
axios.post('/rso/getPuuid', {gameName: gameName, tagline: tagLine}).then((res) => {
168-
setPuuid(res.data.puuid);
169-
}).catch((error) => {return error; })
170166
}
171167
}, [accessToken, refreshToken, RSOAccessToken, RSORefreshToken]);
172168

src/web/src/Pages/user/RiotProfile.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ import { Layout } from '../../Components'
55
const RiotProfile = () => {
66
const Auth = useContext(AuthContext);
77
const [loading, setLoading] = useState(true);
8+
const [matchIds, setMatchIds] = useState<string[]>([]);
9+
10+
const fetchData = async () => {
11+
const region = "na";
12+
const res = await fetch(`https://${region}.api.riotgames.com/val/match/v1/matchlists/by-puuid/${Auth?.puuid}`, {
13+
method: 'GET',
14+
headers: {
15+
// Use an API key that actually allows fetching to this endpoint
16+
'X-Riot-Token': process.env.RIOT_DEVELOPER_API_KEY || ""
17+
}
18+
});
19+
const resJson = await res.json();
20+
const newArray = resJson.data.map((matchObj:any) => matchObj.matchId);
21+
setMatchIds([...matchIds, ...newArray ])
22+
// use /val/match/v1/matches/{matchId} to get more in depth details of each match
23+
}
824

925
useEffect(() => {
1026
// Check if signed in via RSO
@@ -14,6 +30,7 @@ const RiotProfile = () => {
1430
}
1531

1632
setLoading(false);
33+
fetchData();
1734
}, [Auth])
1835

1936
if (loading)
@@ -27,8 +44,8 @@ const RiotProfile = () => {
2744
<div className={'flex flex-row m-2 space-x-4'}>
2845
<img className={'rounded-full w-16 h-16'}
2946
src={`https://ui-avatars.com/api/?background=random&color=fff&name=${Auth?.gameName}`}/>
30-
<div>{'overview'}</div>
31-
<div>{'matches'}</div>
47+
<div>{'Overview'}</div>
48+
<div>{'Recent matches'}</div>
3249
<div>{`info: ${Auth?.gameName}#${Auth?.tagLine} ${Auth?.puuid}`}</div>
3350
</div>
3451
<div className={'animate-pulse'}>

0 commit comments

Comments
 (0)