Skip to content

Commit

Permalink
Revert "Revert "merge escrow data fix to main" (#144)" (#145)
Browse files Browse the repository at this point in the history
This reverts commit b6e473d.
  • Loading branch information
ECWireless authored Jul 4, 2024
1 parent b6e473d commit f8f6aac
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
9 changes: 7 additions & 2 deletions libs/escrow-gql/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import { NETWORK_CONFIG } from '@raidguild/escrow-utils';
import { GraphQLClient } from 'graphql-request';
import _ from 'lodash';

const STUDIO_ID = '78711';
const STUDIO_URL = `https://api.studio.thegraph.com/query/${STUDIO_ID}`;


const graphUrl = (chainId: number = 4) =>
`https://api.thegraph.com/subgraphs/name/${NETWORK_CONFIG[chainId].SUBGRAPH}`;
`${STUDIO_URL}/${NETWORK_CONFIG[chainId].SUBGRAPH}`;

export const SUPPORTED_NETWORKS = _.map(_.keys(NETWORK_CONFIG), _.toNumber);

export const client = (chainId: number) => new GraphQLClient(graphUrl(chainId));

export const v1Client = new GraphQLClient(
'https://api.thegraph.com/subgraphs/name/dan13ram/xdai-smart-invoices'
`${STUDIO_URL}/dan13ram/xdai-smart-invoices` // TODO: deploy v1 subgraph to STUDIO URL // replaced url but it wouldn't work
);
27 changes: 13 additions & 14 deletions libs/escrow-gql/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@ export const getInvoice = async (chainId: number, address: string) => {
if (!isAddress(address)) return null;

try {
const promises = [
client(chainId).request(V2_INVOICE_QUERY, {
address: _.toLower(address),
}),
v1Client.request(INVOICE_QUERY, {
address: _.toLower(address),
}),
];

const result = await Promise.all(promises);
const invoice = _.first(_.compact(_.map(result, 'invoice')));

const result = await client(chainId).request(V2_INVOICE_QUERY, {
address: _.toLower(address),
});
const invoice = _.get(result, 'invoice');
return invoice || null;
} catch (err) {
// eslint-disable-next-line no-console
console.error(err);
return null;
// try v1 client
// TODO: FIX V1 CLIENT
console.log('trying v1 client', err);
const result = v1Client.request(INVOICE_QUERY, {
address: _.toLower(address),
});

const invoice = _.first(_.compact(_.map(result as any, 'invoice'))); // NOT SURE IF IT WORKS ANYMORE, NEED V1 CLIENT SUBGRAPH MIGRATED TO STUDIO URL
return invoice || null;
}
};
6 changes: 3 additions & 3 deletions libs/escrow-utils/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface NetworkConfig {

export const NETWORK_CONFIG: { [key: number]: NetworkConfig } = {
100: {
SUBGRAPH: 'scottrepreneur/smart-invoice-gnosis',
SUBGRAPH: 'smart-invoice-gnosis/v0.0.1',
INVOICE_FACTORY: _.toLower(
'0xdDd96D43b0B2Ca179DCefA58e71798d0ce56c9c8'
) as Hex,
Expand Down Expand Up @@ -95,7 +95,7 @@ export const NETWORK_CONFIG: { [key: number]: NetworkConfig } = {
},
},
1: {
SUBGRAPH: 'psparacino/v1-mainnet-smart-invoices',
SUBGRAPH: 'smart-invoice/v0.0.1',
INVOICE_FACTORY: _.toLower(
'0x5E14cF595e18F91170009946205f8BBa21b323ca'
) as Hex,
Expand Down Expand Up @@ -124,7 +124,7 @@ export const NETWORK_CONFIG: { [key: number]: NetworkConfig } = {
},
},
5: {
SUBGRAPH: 'geovgy/v1-goerli-smart-invoice',
SUBGRAPH: 'geovgy/v1-goerli-smart-invoice', // TODO: remove goerli- replace with sepolia?
WRAPPED_NATIVE_TOKEN: _.toLower(
'0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6'
) as Hex,
Expand Down

0 comments on commit f8f6aac

Please sign in to comment.