Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #95 from factchain/remove_get_contract
Browse files Browse the repository at this point in the history
[extension] remove get contracts
  • Loading branch information
YBadiss authored Mar 6, 2024
2 parents 51fcf98 + aeca83a commit c5c7e6b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 48 deletions.
6 changes: 0 additions & 6 deletions fc-community-backend/apps/api/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { AppService } from "./app.service";
import {
NotesResponse,
XSignedNoteIDResponse,
ContractsResponse,
} from "./factchain-core/types";

import { ThrottlerGuard } from "@nestjs/throttler";
Expand All @@ -31,11 +30,6 @@ export class AppController {
return this.appService.getVersion();
}

@Get("/_contracts")
getContracts(): ContractsResponse {
return { contracts: this.appService.getContracts() };
}

@Get("/notes")
@UseGuards(ThrottlerGuard)
async getNotes(
Expand Down
10 changes: 0 additions & 10 deletions fc-community-backend/apps/api/src/factchain-core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ export type NotesResponse = {
notes: Array<Note>;
};

export type ContractAddresses = {
main: string;
nft: string;
sft: string;
x: string;
};

export type ContractsResponse = {
contracts: ContractAddresses;
};

export type FactChainEvent =
| "ReserveFunded"
Expand Down
10 changes: 0 additions & 10 deletions fc-community-backend/apps/shared/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ export type NotesResponse = {
notes: Array<Note>;
};

export type ContractAddresses = {
main: string;
nft: string;
sft: string;
x: string;
};

export type ContractsResponse = {
contracts: ContractAddresses;
};

export type FactChainEvent =
| "ReserveFunded"
Expand Down
19 changes: 0 additions & 19 deletions fc-community-extension/src/utils/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,6 @@ export const createXNoteId = async (noteUrl, content) => {
}
};

export const getContracts = async () => {
let fullUrl = `${BACKEND_URL}/_contracts`;
console.log('Getting contracts', fullUrl);

try {
const response = await fetch(fullUrl, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
const data = await response.json();
return data.contracts;
} catch (error) {
console.error('Error fetching contracts:', error);
throw error;
}
};

export const awaitOpenSeaUrl = async (openseaUrl) => {
console.log('Waiting for opensea url to be ok', openseaUrl);
let retry = 10;
Expand Down
27 changes: 24 additions & 3 deletions fc-community-extension/src/utils/web3.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
FC_NFT_CONTRACT_ABI,
FC_SFT_CONTRACT_ABI,
} from './constants';
import { getContracts } from './backend';
import abiDecoder from 'abi-decoder';

abiDecoder.addABI(FC_MAIN_CONTRACT_ABI);
Expand Down Expand Up @@ -72,14 +71,36 @@ export const createFactchainProvider = async () => {
});
return accounts;
};

const getContractAddress = (contractName) => {
// mapping contractName to fixed proxy contract
// doesn't break the upgradeability
// because proxy should never be upgraded to another addess
switch (contractName) {
case 'main':
return '0x3b5946b3bd79c2B211E49c3149872f1d66223AE7';
case 'x':
return '0xaC51f5E2664aa966c678Dc935E0d853d3495A48C';
case 'sft':
return '0xF9408EB2C2219E28aEFB32035c49d491880650A2';
case 'nft':
return '0x5818764B4272f4eCff170216abE99D36c0c41622';
default:
// should never happen
// caller isn't expected to catch this error
throw new Error(`Unknown Contract ${contractName}`);
}
};

const getContract = async (contractName, contractAbi) => {
const ethersProvider = new ethers.BrowserProvider(provider);
const signer = await ethersProvider.getSigner();
const contractAddress = (await getContracts())[contractName];
const contractAddress = getContractAddress(contractName);
return new ethers.Contract(contractAddress, contractAbi, signer);
};

const onContractEvents = async (contractName, topics, callback) => {
const contractAddress = (await getContracts())[contractName];
const contractAddress = getContractAddress(contractName);
filter = {
address: contractAddress,
topics: topics.map(utils.id),
Expand Down

0 comments on commit c5c7e6b

Please sign in to comment.