Added Banking View, displaying balance and transactions
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
query Continents {
|
||||
countries_continents {
|
||||
name
|
||||
code
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
query Countries($filter: countries_CountryFilterInput) {
|
||||
countries_countries(filter: $filter) {
|
||||
code
|
||||
name
|
||||
capital
|
||||
}
|
||||
}
|
22
.wundergraph/operations/getBalance.ts
Normal file
22
.wundergraph/operations/getBalance.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { createOperation, z } from '../generated/wundergraph.factory';
|
||||
import axios from 'axios';
|
||||
|
||||
export default createOperation.query({
|
||||
input: z.object({
|
||||
address: z.string(),
|
||||
}),
|
||||
handler: async ({ input }) => {
|
||||
const { data } = await axios.get('https://api.gnosisscan.io/api', {
|
||||
params: {
|
||||
module: 'account',
|
||||
action: 'balance',
|
||||
address: input.address,
|
||||
tag: 'latest',
|
||||
apikey: process.env.GNOSISSCAN_API,
|
||||
},
|
||||
});
|
||||
return {
|
||||
balance: parseFloat(data.result),
|
||||
};
|
||||
},
|
||||
});
|
27
.wundergraph/operations/getTransactions.ts
Normal file
27
.wundergraph/operations/getTransactions.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { createOperation, z } from '../generated/wundergraph.factory';
|
||||
import axios from 'axios';
|
||||
|
||||
export default createOperation.query({
|
||||
input: z.object({
|
||||
address: z.string(),
|
||||
}),
|
||||
handler: async ({ input }) => {
|
||||
const { data } = await axios.get('https://api.gnosisscan.io/api', {
|
||||
params: {
|
||||
module: 'account',
|
||||
action: 'txlist',
|
||||
address: input.address,
|
||||
startblock: 0,
|
||||
endblock: 'latest',
|
||||
sort: 'desc',
|
||||
apikey: process.env.GNOSISSCAN_API,
|
||||
},
|
||||
});
|
||||
return {
|
||||
transactions: data.result.map(transaction => ({
|
||||
...transaction,
|
||||
timestamp: new Date(transaction.timeStamp * 1000).toISOString(),
|
||||
})),
|
||||
};
|
||||
},
|
||||
});
|
@ -4,15 +4,11 @@ import operations from './wundergraph.operations';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import dotenv from 'dotenv';
|
||||
import axios from 'axios';
|
||||
dotenv.config();
|
||||
|
||||
const directusSchema = fs.readFileSync(path.join(path.resolve(), './schemas/directus.graphql'), 'utf8');
|
||||
|
||||
const countries = introspect.graphql({
|
||||
apiNamespace: 'countries',
|
||||
url: 'https://countries.trevorblades.com/',
|
||||
});
|
||||
|
||||
const spaceX = introspect.graphql({
|
||||
apiNamespace: 'spacex',
|
||||
url: 'https://spacex-api.fly.dev/graphql/',
|
||||
@ -28,7 +24,7 @@ const directus = introspect.graphql({
|
||||
|
||||
// configureWunderGraph emits the configuration
|
||||
configureWunderGraphApplication({
|
||||
apis: [countries, spaceX, directus],
|
||||
apis: [spaceX, directus],
|
||||
server,
|
||||
operations,
|
||||
generate: {
|
||||
@ -65,6 +61,6 @@ configureWunderGraphApplication({
|
||||
},
|
||||
},
|
||||
authorization: {
|
||||
roles: ['admin'],
|
||||
roles: ['owner'],
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user