Skip to content

Commit

Permalink
Merge pull request #277 from sunrise-stake/chore/remove-obsolete-code
Browse files Browse the repository at this point in the history
Removed obsolete code after the forest retrieval refactor
  • Loading branch information
dankelleher authored Aug 1, 2023
2 parents a69c678 + 9564c63 commit 250fb5a
Show file tree
Hide file tree
Showing 34 changed files with 176 additions and 348 deletions.
69 changes: 0 additions & 69 deletions packages/app/src/api/db.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,12 @@
import {
type GetNeighboursResponse,
type Mint,
type MintResponse,
type MongoResponse,
type NeighbourEntry,
type RawGetNeighboursResponse,
type RawNeighbourEntry,
type Transfer,
type TransferResponse,
} from "./types";
import { PublicKey } from "@solana/web3.js";
import mintStub from "./stubs/mints.json";
import sendingStub from "./stubs/sendings.json";
import receiptStub from "./stubs/receipts.json";

const STUB_DB = false;
const STUBS = {
mints: mintStub,
sender: sendingStub,
recipient: receiptStub,
};
const GET_NEIGHBOURS_URL = process.env.REACT_APP_GET_NEIGHBOURS_URL ?? "";
const MONGODB_API_URL = process.env.REACT_APP_MONGODB_API_URL ?? "";
const MONGODB_READ_TOKEN = process.env.REACT_APP_MONGODB_READ_TOKEN ?? "";
const buildTransferRecord = (transfer: TransferResponse): Transfer => ({
timestamp: new Date(transfer.timestamp),
sender: new PublicKey(transfer.sender),
recipient: new PublicKey(transfer.recipient),
amount: transfer.amount,
});
const buildMintRecord = (mint: MintResponse): Mint => ({
timestamp: new Date(mint.timestamp),
recipient: new PublicKey(mint.recipient),
sender: mint.sender !== undefined ? new PublicKey(mint.sender) : undefined,
amount: mint.amount,
});

const fromRawNeighbourEntry = (
rawEntry: RawNeighbourEntry
Expand Down Expand Up @@ -65,44 +37,3 @@ export const getNeighbours = async (
),
},
}));

const getDBData = async <T>(
collection: "mints" | "transfers",
types: Array<"recipient" | "sender">,
address: PublicKey
): Promise<MongoResponse<T>> => {
if (STUB_DB) {
return (
collection === "mints"
? STUBS.mints
: types.flatMap((type) => STUBS[type])
) as MongoResponse<T>;
}
return fetch(`${MONGODB_API_URL}/action/find`, {
method: "POST",
headers: {
"api-key": MONGODB_READ_TOKEN,
"Content-Type": "application/json",
},
body: JSON.stringify({
dataSource: "Cluster0",
database: "gsol-tracker",
collection,
filter: {
$or: types.map((type) => ({
[type]: address.toString(),
})),
},
}),
}).then(async (resp) => resp.json());
};
export const getAccountMints = async (address: PublicKey): Promise<Mint[]> =>
getDBData<MintResponse>("mints", ["sender", "recipient"], address)
.then((resp) => resp.documents)
.then((mints) => mints.map(buildMintRecord));
export const getAccountTransfers = async (
address: PublicKey
): Promise<Transfer[]> =>
getDBData<TransferResponse>("transfers", ["sender", "recipient"], address)
.then((resp) => resp.documents)
.then((transfers) => transfers.map(buildTransferRecord));
22 changes: 0 additions & 22 deletions packages/app/src/api/stubs/mints.json

This file was deleted.

3 changes: 0 additions & 3 deletions packages/app/src/api/stubs/receipts.json

This file was deleted.

46 changes: 0 additions & 46 deletions packages/app/src/api/stubs/sendings.json

This file was deleted.

32 changes: 0 additions & 32 deletions packages/app/src/api/types.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
import { type PublicKey } from "@solana/web3.js";

export interface MintResponse {
timestamp: string;
sender?: string; // the wallet that pays for the mint (assume = the recipient if missing)
recipient: string;
amount: number;
}

export interface TransferResponse {
timestamp: string;
sender: string;
recipient: string;
amount: number;
}

export interface BalanceDetails {
address: PublicKey;
balance: number;
Expand Down Expand Up @@ -60,24 +46,6 @@ export interface GetNeighboursResponse {
lastTransfer: Date;
}

export interface MongoResponse<T> {
documents: T[];
}

export interface Mint {
timestamp: Date;
sender?: PublicKey; // the wallet that pays for the mint (assume = the recipient if missing)
recipient: PublicKey; // the wallet that receives the minted gSOL
amount: number;
}

export interface Transfer {
timestamp: Date;
sender: PublicKey;
recipient: PublicKey;
amount: number;
}

export type ParentRelationship = "PARENT_IS_SENDER" | "PARENT_IS_RECIPIENT";

export interface TreeNode {
Expand Down
Loading

0 comments on commit 250fb5a

Please sign in to comment.