Skip to content

Commit

Permalink
Merge branch 'main' into ag/feat/FE-567
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgeron authored Sep 25, 2024
2 parents 32dac21 + c30391f commit a5e5dfe
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/graphql/database/1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ create table indexer.assets_contracts (
asset_id text not null,
contract_id text not null,
transaction_id text not null,
sub_id text,
name text,
symbol text,
decimals integer,
Expand Down
4 changes: 3 additions & 1 deletion packages/graphql/src/application/uc/IndexAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class IndexAsset {
assetId,
contractId: receipt.id,
transactionId: transaction.id,
subId: receipt.subId,
name: null,
symbol: null,
decimals: null,
Expand Down Expand Up @@ -50,11 +51,12 @@ export default class IndexAsset {
}
try {
connection.query(
'insert into indexer.assets_contracts (asset_id, contract_id, transaction_id, name, symbol, decimals, error) values ($1, $2, $3, $4, $5, $6, $7) on conflict do nothing',
'insert into indexer.assets_contracts (asset_id, contract_id, transaction_id, sub_id, name, symbol, decimals, error) values ($1, $2, $3, $4, $5, $6, $7, $8) on conflict do nothing',
[
asset.assetId,
asset.contractId,
asset.transactionId,
asset.subId,
asset.name,
asset.symbol,
asset.decimals,
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/graphql/generated/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const anAsset = (overrides?: Partial<GQLAsset>): { __typename: 'Asset' }
icon: overrides && overrides.hasOwnProperty('icon') ? overrides.icon! : 'explicabo',
name: overrides && overrides.hasOwnProperty('name') ? overrides.name! : 'dolorem',
networks: overrides && overrides.hasOwnProperty('networks') ? overrides.networks! : [anAssetNetworkEthereum()],
subId: overrides && overrides.hasOwnProperty('subId') ? overrides.subId! : 'omnis',
symbol: overrides && overrides.hasOwnProperty('symbol') ? overrides.symbol! : 'quaerat',
verified: overrides && overrides.hasOwnProperty('verified') ? overrides.verified! : false,
};
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/graphql/generated/sdk-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type GQLAsset = {
icon?: Maybe<Scalars['String']['output']>;
name?: Maybe<Scalars['String']['output']>;
networks?: Maybe<Array<Maybe<GQLAssetNetwork>>>;
subId?: Maybe<Scalars['String']['output']>;
symbol?: Maybe<Scalars['String']['output']>;
verified?: Maybe<Scalars['Boolean']['output']>;
};
Expand Down
4 changes: 3 additions & 1 deletion packages/graphql/src/graphql/generated/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type GQLAsset = {
icon?: Maybe<Scalars['String']['output']>;
name?: Maybe<Scalars['String']['output']>;
networks?: Maybe<Array<Maybe<GQLAssetNetwork>>>;
subId?: Maybe<Scalars['String']['output']>;
symbol?: Maybe<Scalars['String']['output']>;
verified?: Maybe<Scalars['Boolean']['output']>;
};
Expand Down Expand Up @@ -1508,7 +1509,7 @@ export type GQLAssetQueryVariables = Exact<{
}>;


export type GQLAssetQuery = { __typename: 'Query', asset?: { __typename: 'Asset', assetId?: string | null, contractId?: string | null, name?: string | null, symbol?: string | null, decimals?: string | null, icon?: string | null, verified?: boolean | null } | null };
export type GQLAssetQuery = { __typename: 'Query', asset?: { __typename: 'Asset', assetId?: string | null, contractId?: string | null, subId?: string | null, name?: string | null, symbol?: string | null, decimals?: string | null, icon?: string | null, verified?: boolean | null } | null };

export type GQLBalanceItemFragment = { __typename: 'Balance', amount: string, assetId: string, owner: string, utxos?: Array<{ __typename: 'UtxoItem', amount: string, blockCreated?: string | null, txCreatedIdx?: string | null, utxoId: string } | null> | null };

Expand Down Expand Up @@ -2109,6 +2110,7 @@ export const AssetDocument = gql`
asset(assetId: $assetId) {
assetId
contractId
subId
name
symbol
decimals
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/graphql/queries/sdk/asset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ query asset($assetId: String!){
asset (assetId: $assetId) {
assetId
contractId
subId
name
symbol
decimals
Expand Down
13 changes: 6 additions & 7 deletions packages/graphql/src/graphql/resolvers/PublicResolver.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Provider } from 'fuels';
import { env } from '~/config';
import VerifiedAssets from '~/infra/cache/VerifiedAssets';
import AssetDAO from '~/infra/dao/AssetDAO';

type Params = {
Expand All @@ -20,10 +21,8 @@ export class PublicResolver {
const assetDAO = new AssetDAO();
const provider = await Provider.create(env.get('FUEL_PROVIDER'));
const chainId = provider.getChainId();
const response = await fetch(
'https://verified-assets.fuel.network/assets.json',
);
const verifiedAssets = await response.json();
const nonVerifiedAsset = await assetDAO.getByAssetId(_params.assetId);
const verifiedAssets = await VerifiedAssets.getInstance().fetch();
for (const verifiedAsset of verifiedAssets) {
for (const network of verifiedAsset.networks) {
if (network.type === 'fuel') {
Expand All @@ -43,16 +42,16 @@ export class PublicResolver {
const asset = Object.assign(verifiedAsset, {
assetId: _params.assetId,
contractId: network.contractId,
subId: nonVerifiedAsset?.subId,
decimals: network.decimals,
verified: true,
});
return asset;
}
}
}
const asset = await assetDAO.getByAssetId(_params.assetId);
if (!asset) return;
return Object.assign(asset, {
if (!nonVerifiedAsset) return;
return Object.assign(nonVerifiedAsset, {
verified: false,
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/graphql/schemas/explorer.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ type BlocksDashboardConnection {
type Asset {
assetId: String
contractId: String
subId: String
name: String
symbol: String
decimals: U64
Expand Down
31 changes: 31 additions & 0 deletions packages/graphql/src/infra/cache/VerifiedAssets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default class VerifiedAssets {
static instance: VerifiedAssets;
private lastDate?: Date;
private assets: any;

private constructor() {}

async fetch() {
const now = new Date();
if (
!this.lastDate ||
!this.assets ||
now.getTime() - this.lastDate.getTime() > 60000
) {
this.lastDate = new Date();
const response = await fetch(
'https://verified-assets.fuel.network/assets.json',
);
this.assets = await response.json();
return this.assets;
}
return this.assets;
}

static getInstance() {
if (!VerifiedAssets.instance) {
VerifiedAssets.instance = new VerifiedAssets();
}
return VerifiedAssets.instance;
}
}
1 change: 1 addition & 0 deletions packages/graphql/src/infra/dao/AssetDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class BlockDAO {
return {
assetId: assetData.asset_id,
contractId: assetData.contract_id,
subId: assetData.sub_id,
name: assetData.name,
symbol: assetData.symbol,
decimals: assetData.decimals,
Expand Down

0 comments on commit a5e5dfe

Please sign in to comment.