Skip to content

Commit

Permalink
refactor: remove firebase
Browse files Browse the repository at this point in the history
fix: extract v2 functions
  • Loading branch information
osiastedian committed Dec 11, 2024
1 parent d26ebd1 commit b06fc1c
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 3,911 deletions.
5 changes: 0 additions & 5 deletions .firebaserc

This file was deleted.

41 changes: 40 additions & 1 deletion .github/workflows/ghcr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
docker:
permissions:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
Expand All @@ -18,6 +18,7 @@ jobs:

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
Expand All @@ -32,6 +33,7 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
Expand All @@ -54,3 +56,40 @@ jobs:
with:
name: metadata
path: metadata.json

deploy-staging:
needs: docker
environment:
name: staging
permissions:
deployments: write
contents: read
runs-on: ubuntu-latest
steps:
- name: Download metadata
uses: actions/download-artifact@v4
with:
name: metadata
path: ./metadata

- name: Read Metadata
id: read-metadata
run: |
cd metadata
meta=$(cat metadata.json)
echo "::set-output name=tags::$(echo "$meta" | jq -r '.target["docker-metadata-action"].tags | join(",")')"
shell: bash

- name: Deploy Frontend Service
uses: appleboy/ssh-action@v0.1.9
env:
IMAGE_TAG: ${{ steps.read-metadata.outputs.tags }}
with:
host: ${{ secrets.HETZNER_STAGING_HOST }}
username: root
key: ${{ secrets.HETZNER_SSH_KEY }}
script: |
export FRONTEND_IMAGE="$(echo ${{ env.IMAGE_TAG }} | cut -d ',' -f 2)"
cd /root/bridge
docker-compose pull frontend
docker-compose up -d frontend
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ yarn-error.log*
*.tsbuildinfo


#firebase

*.log

.yarn
Expand Down
39 changes: 15 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ https://bridge.syscoin.org/

### Bridge UI

The bridge UI is a ReactJS application that allows users to interact with the bridge. It is a NextJS application that uses Firebase for authentication and storage. This allows users to interact with the bridge without having to install any software.
The bridge UI is a ReactJS application that allows users to interact with the bridge. It is a NextJS application that uses Mongodb for storage. This allows users to interact with the bridge without having to install any software.

Each step taken on the Bridge is stored in Firebase Firestore. This allows the user to resume the process at any time.
Each step taken on the Bridge is stored in MongoDB. This allows the user to resume the process at any time.

## How to run

### Prerequisites

- NodeJS 16+ (recommneded to use `nvm` to install NodeJS)
- Firebase Emulator (recommended to use `npm install -g firebase-tools` to install Firebase Emulator)
- NodeJS 16+ (recommended to use `nvm` to install NodeJS)
- Yarn (recommended to use `npm install -g yarn` to install Yarn)

### Install dependencies
Expand All @@ -47,14 +46,6 @@ Each step taken on the Bridge is stored in Firebase Firestore. This allows the u
yarn install
```

### Run Firebase Emulator

Runs Firebase Emulator on port `4000`

```bash
yarn firebase:dev
```

### Run Dev Server

Runs NextJS Dev Server on port `3000`
Expand All @@ -79,18 +70,18 @@ docker build -t syscoin/bridge .

### Environment Variables (for Production Docker)

| Name | Description | Default |
| ------------------------------ | ---------------------------- | ------- |
| `FIREBASE_API_KEY` | Firebase API Key | `""` |
| `FIREBASE_AUTH_DOMAIN` | Firebase Auth Domain | `""` |
| `FIREBASE_PROJECT_ID` | Firebase Project ID | `""` |
| `FIREBASE_STORAGE_BUCKET` | Firebase Storage Bucket | `""` |
| `FIREBASE_MESSAGING_SENDER_ID` | Firebase Messaging Sender ID | `""` |
| `FIREBASE_APP_ID` | Firebase App ID | `""` |
| `FIREBASE_MEASUREMENT_ID` | Firebase Measurement ID | `""` |
| `FIREBASE_AUTH_EMAIL` | Firebase Auth Email | `""` |
| `FIREBASE_AUTH_PASSWORD` | Firebase Auth Password | `""` |
| `FIREBASE_AUTH_UID` | Firebase Auth UID | `""` |
| Name | Description | Default |
| ------------------------------- | --------------------------------- | ------- |
| `MONGODB_URI` | MongoDB URI | |
| `CONFIRM_TRANSACTION_TIMEOUTS` | Description | Default |
| `MINIMUM_AMOUNT` | Minimum amount of SYS to transfer | 100 |
| `ADMIN_API_KEY` | Admin API Key | |
| `SECRET_COOKIE_PASSWORD` | Secret Cookie Password | |
| `NEXT_PUBLIC_NEVM_RPC_URL` | NEVM RPC URL | |
| `NEXT_PUBLIC_NEVM_EXPLORER` | NEVM Explorer URL | |
| `NEXT_PUBLIC_IS_TESTNET` | Is Testnet | |
| `NEXT_PUBLIC_CHAIN_ID` | Chain ID | |
| `NEXT_PUBLIC_BLOCKBOOK_API_URL` | Blockbook API URL | |

## Contact

Expand Down
2 changes: 0 additions & 2 deletions api/services/admin-transfer/handle-burn-sys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { AddBurnSysLogRequestPayload } from "api/types/admin/transfer/add-log";
import dbConnect from "lib/mongodb";
import { NextApiRequest, NextApiResponse } from "next";
import TransferModel from "models/transfer";
import { BlockbookAPIURL } from "@contexts/Transfer/constants";
import { utils as syscoinUtils } from "syscoinjs-lib";
import {
ITransferLog,
SYS_TO_ETH_TRANSFER_STATUS,
Expand Down
39 changes: 2 additions & 37 deletions api/services/transfer.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
import { ITransfer } from "@contexts/Transfer/types";
import { UserCredential, signInWithEmailAndPassword } from "firebase/auth";
import firebase from "firebase-setup";
import { doc, getDoc } from "firebase/firestore";
import TransferModel from "models/transfer";
import { SponsorWalletService } from "./sponsor-wallet";

export class TransferService {
private isAuthenticated = false;
private sponsorWalletService = new SponsorWalletService();
constructor() {
this.authenticate();
}
private async authenticate() {
if (this.isAuthenticated) {
return;
}
if (process.env.NODE_ENV !== "development" && firebase.auth) {
await signInWithEmailAndPassword(
firebase.auth,
process.env.FIREBASE_AUTH_EMAIL!,
process.env.FIREBASE_AUTH_PASSWORD!
).then((userCredential) => {
this.isAuthenticated = Boolean(userCredential as UserCredential);
});
}
}
constructor() {}

async getAll(params: Partial<ITransfer>): Promise<ITransfer[]> {
const filters: (keyof ITransfer)[] = [
Expand All @@ -47,25 +27,10 @@ export class TransferService {
const transfer = await TransferModel.findOne({ id });

if (!transfer) {
return this.getTransferFirebase(id);
}

return transfer as unknown as ITransfer;
}

async getTransferFirebase(id: string): Promise<ITransfer> {
await this.authenticate();
const document = await getDoc(
doc(firebase.firestore, "transfers", id as string)
);

if (!document.exists()) {
throw new Error("Transfer not found");
}

const transferData = document.data() as ITransfer;

return this.upsertTransfer(transferData);
return transfer as unknown as ITransfer;
}

async upsertTransfer(transfer: ITransfer): Promise<ITransfer> {
Expand Down
16 changes: 7 additions & 9 deletions components/Bridge/UTXOStepWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { usePaliWalletV2 } from "@contexts/PaliWallet/usePaliWallet";
import {
usePaliWallet,
usePaliWalletV2,
} from "@contexts/PaliWallet/usePaliWallet";
import { Button } from "@mui/material";
import { isValidSYSAddress } from "@pollum-io/sysweb3-utils";

Expand All @@ -7,14 +10,9 @@ type UTXOStepWrapperProps = {
};

const UTXOStepWrapper: React.FC<UTXOStepWrapperProps> = ({ children }) => {
const {
version,
isBitcoinBased,
switchTo,
connectedAccount,
connectWallet,
changeAccount,
} = usePaliWalletV2();
const { version, connectedAccount, connectWallet } = usePaliWallet();

const { isBitcoinBased, switchTo, changeAccount } = usePaliWalletV2();

if (version === "v2" && !isBitcoinBased) {
return (
Expand Down
37 changes: 0 additions & 37 deletions firebase-setup.ts

This file was deleted.

15 changes: 0 additions & 15 deletions firebase.json

This file was deleted.

6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"firebase:dev": "firebase emulators:start"
"lint": "next lint"
},
"dependencies": {
"@emotion/react": "^11.10.6",
Expand All @@ -23,8 +22,6 @@
"bitcoinjs-lib": "^6.0.1",
"date-fns": "^2.30.0",
"eslint-plugin-unused-imports": "^3.0.0",
"firebase": "^9.22.1",
"firebase-admin": "^10.2.0",
"iron-session": "^6.3.1",
"mongoose": "^7.5.0",
"next": "13.2.4",
Expand All @@ -42,7 +39,6 @@
"@types/react-dom": "18.0.3",
"eslint": "8.15.0",
"eslint-config-next": "12.1.6",
"firebase-tools": "^11.0.1",
"jest": "^29.7.0",
"ts-jest": "^29.1.1",
"typescript": "4.6.4"
Expand Down
24 changes: 2 additions & 22 deletions pages/api/transfer/[id].ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import firebase from "firebase-setup";
import type { NextApiRequest, NextApiResponse } from "next";
import { doc, getDoc } from "firebase/firestore";
import { signInWithEmailAndPassword } from "firebase/auth";
import { TransferService } from "api/services/transfer";
import dbConnect from "lib/mongodb";

Expand All @@ -14,25 +11,8 @@ const getRequest = async (req: NextApiRequest, res: NextApiResponse) => {
return res.status(400).json({ message: "Missing id" });
}

try {
const transfer = await transferService.getTransfer(id as string);
return res.status(200).json(transfer);
} catch (e) {}

if (process.env.NODE_ENV !== "development" && firebase.auth) {
await signInWithEmailAndPassword(
firebase.auth,
process.env.FIREBASE_AUTH_EMAIL!,
process.env.FIREBASE_AUTH_PASSWORD!
);
}
const document = await getDoc(
doc(firebase.firestore, "transfers", id as string)
);
if (!document.exists()) {
return res.status(404).json({ message: "Transfer not found" });
}
res.status(200).json(document.data());
const transfer = await transferService.getTransfer(id as string);
return res.status(200).json(transfer);
};

const patchRequest = async (req: NextApiRequest, res: NextApiResponse) => {
Expand Down
16 changes: 0 additions & 16 deletions pages/api/transfer/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { NextApiHandler } from "next";
import { where, QueryFilterConstraint } from "firebase/firestore";
import { TransferService } from "api/services/transfer";
import dbConnect from "lib/mongodb";
import { ITransfer } from "@contexts/Transfer/types";
Expand All @@ -9,21 +8,6 @@ const transferService = new TransferService();
const getAll: NextApiHandler = async (req, res) => {
const { nevm, utxo, version } = req.query;

const queryConstraints: QueryFilterConstraint[] = [];

if (nevm) {
queryConstraints.push(where("nevmAddress", "==", nevm));
}

if (utxo) {
queryConstraints.push(where("utxoXpub", "==", utxo));
queryConstraints.push(where("utxoAddress", "==", utxo));
}

if (queryConstraints.length === 0) {
return res.status(400).json({ message: "Some parameters are missing" });
}

await dbConnect();

const dbTransfer = await transferService.getAll({
Expand Down
Loading

0 comments on commit b06fc1c

Please sign in to comment.