Skip to content

Commit

Permalink
refactor: radix api and env defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
icfor committed Nov 21, 2023
1 parent aa9bd26 commit 7bcf0ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
7 changes: 5 additions & 2 deletions .env.defaults
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PUBLIC_URL=http://localhost:4000
NODE_ENV=development
MAIL_GUN_PW=...
MAIL_GUN_USER=...
MAX_OVER_TIME_DURATION=2d
NODE_ENV=development
PROMETHEUS_URL=...
RADIX_URL=...
7 changes: 1 addition & 6 deletions src/graphql/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,7 @@ export const resolvers = {
__: any,
{ dataSources }: ContextValue,
) => {
const JSONbody = {
network_identifier: {
network: "mainnet",
},
};
const response = await dataSources.radixAPI.getTotalRadixSupply(JSONbody);
const response = await dataSources.radixAPI.getTotalRadixSupply();
const { token } = response;
const { token_supply } = token;
const val = {
Expand Down
16 changes: 13 additions & 3 deletions src/graphql/routes/radix-api.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { RESTDataSource } from "@apollo/datasource-rest";
import type { KeyValueCache } from "@apollo/utils.keyvaluecache";

const { RADIX_URL } = process.env;

if (!RADIX_URL) {
throw new Error("Missing RADIX_URL env var");
}

export class RadixAPI extends RESTDataSource {
override baseURL = `${process.env.RADIX_URL}/`;
override baseURL = `${(RADIX_URL as string).replace(/\/$/, "")}/`;

constructor(options: { cache: KeyValueCache }) {
super(options); // this sends our server's `cache` through
}

async getTotalRadixSupply(body: any) {
async getTotalRadixSupply() {
return this.post("token/native", {
headers: {
"Content-Type": "application/json",
},
body,
body: JSON.stringify({
network_identifier: {
network: "mainnet",
},
}),
});
}

Expand Down

0 comments on commit 7bcf0ba

Please sign in to comment.