-
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.
feat: styling and graphql improvements
- Loading branch information
1 parent
a58d327
commit 992e837
Showing
13 changed files
with
165 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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,82 @@ | ||
import { | ||
GetAggregatedAccountDataDocument, | ||
type GetAggregatedAccountDataQuery, | ||
} from '@/__generated__/ees/graphql'; | ||
import { getGraphqlApiUrl } from './getGraphqlApiUrl'; | ||
|
||
type GetTopEndorsersAndDonatorsDocument = { | ||
totalEndorsementsReceived: string; | ||
totalEndorsementsSent: string; | ||
totalDonationsReceived: string; | ||
totalDonationsSent: string; | ||
error: string | null; | ||
}; | ||
|
||
export const getAggregatedAccountData = async ({ | ||
chainId, | ||
account, | ||
}: { | ||
chainId: number; | ||
account: string; | ||
}): Promise<GetTopEndorsersAndDonatorsDocument> => { | ||
try { | ||
const graphqlUrl = getGraphqlApiUrl(chainId); | ||
|
||
const result = await fetch(graphqlUrl, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: GetAggregatedAccountDataDocument, | ||
variables: { | ||
account, | ||
}, | ||
}), | ||
// Cache for 1 minute | ||
next: { revalidate: 60 }, | ||
}); | ||
|
||
// Check if request was successful | ||
if (!result.ok) { | ||
return { | ||
totalEndorsementsReceived: '0', | ||
totalEndorsementsSent: '0', | ||
totalDonationsReceived: '0', | ||
totalDonationsSent: '0', | ||
error: 'Failed to fetch data', | ||
}; | ||
} | ||
|
||
const jsonResponse = await result.json(); | ||
|
||
// Check if we successfully decoded the response | ||
if (!jsonResponse) { | ||
return { | ||
totalEndorsementsReceived: '0', | ||
totalEndorsementsSent: '0', | ||
totalDonationsReceived: '0', | ||
totalDonationsSent: '0', | ||
error: 'Failed to fetch data', | ||
}; | ||
} | ||
|
||
const data = jsonResponse.data as GetAggregatedAccountDataQuery; | ||
|
||
return { | ||
totalEndorsementsReceived: data.account?.totalEndorsementsReceived ?? '0', | ||
totalEndorsementsSent: data.account?.totalEndorsementsSent ?? '0', | ||
totalDonationsReceived: data.account?.totalDonationsReceived ?? '0', | ||
totalDonationsSent: data.account?.totalDonationsSent ?? '0', | ||
error: null, | ||
}; | ||
} catch (error) { | ||
return { | ||
totalEndorsementsReceived: '0', | ||
totalEndorsementsSent: '0', | ||
totalDonationsReceived: '0', | ||
totalDonationsSent: '0', | ||
error: 'Failed to fetch data', | ||
}; | ||
} | ||
}; |
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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './getGraphqlApiUrl'; | ||
export * from './getTopEndorsersAndDonators'; | ||
export * from './getAggregatedAccountData'; |
9 changes: 9 additions & 0 deletions
9
packages/dapp/src/lib/graphql/ees/getAggregatedAccountData.query.graphql
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 @@ | ||
query GetAggregatedAccountData($account: ID!) { | ||
account(id: $account) { | ||
id | ||
totalEndorsementsReceived | ||
totalEndorsementsSent | ||
totalDonationsReceived | ||
totalDonationsSent | ||
} | ||
} |
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