aboutsummaryrefslogblamecommitdiffstats
path: root/packages/website/ts/utils/backend_client.ts
blob: 835a6ef4d33ba34c8f3bbcd29d610c0c9627af85 (plain) (tree)
1
2
3
4
5
6
7
8
9
                            
 






                              
                                                  
                                       

                                                    
                              
                                  
                                      
                              
                                                                                 


                                                             
                                                                                                          

                      



                                                                                               


                                                                                       
         
                                                          
                             
                                       
          
                                                                                                              

                      
                                                                        
                                                                                                   

                      
                                                                       
                                                                                               

                      
                                                                        



                                                                                                                      
                      
      
  
import * as _ from 'lodash';

import {
    ArticlesBySection,
    WebsiteBackendGasInfo,
    WebsiteBackendJobInfo,
    WebsiteBackendPriceInfo,
    WebsiteBackendRelayerInfo,
} from 'ts/types';
import { fetchUtils } from 'ts/utils/fetch_utils';
import { utils } from 'ts/utils/utils';

const ETH_GAS_STATION_ENDPOINT = '/eth_gas_station';
const JOBS_ENDPOINT = '/jobs';
const PRICES_ENDPOINT = '/prices';
const RELAYERS_ENDPOINT = '/relayers';
const WIKI_ENDPOINT = '/wiki';
const SUBSCRIBE_SUBSTACK_NEWSLETTER_ENDPOINT = '/newsletter_subscriber/substack';

export const backendClient = {
    async getGasInfoAsync(): Promise<WebsiteBackendGasInfo> {
        const result = await fetchUtils.requestAsync(utils.getBackendBaseUrl(), ETH_GAS_STATION_ENDPOINT);
        return result;
    },
    async getJobInfosAsync(): Promise<WebsiteBackendJobInfo[]> {
        const result = await fetchUtils.requestAsync(utils.getBackendBaseUrl(), JOBS_ENDPOINT);
        return result;
    },
    async getPriceInfoAsync(tokenSymbols: string[]): Promise<WebsiteBackendPriceInfo> {
        if (_.isEmpty(tokenSymbols)) {
            return {};
        }
        const joinedTokenSymbols = tokenSymbols.join(',');
        const queryParams = {
            tokens: joinedTokenSymbols,
        };
        const result = await fetchUtils.requestAsync(utils.getBackendBaseUrl(), PRICES_ENDPOINT, queryParams);
        return result;
    },
    async getRelayerInfosAsync(): Promise<WebsiteBackendRelayerInfo[]> {
        const result = await fetchUtils.requestAsync(utils.getBackendBaseUrl(), RELAYERS_ENDPOINT);
        return result;
    },
    async getWikiArticlesBySectionAsync(): Promise<ArticlesBySection> {
        const result = await fetchUtils.requestAsync(utils.getBackendBaseUrl(), WIKI_ENDPOINT);
        return result;
    },
    async subscribeToNewsletterAsync(email: string): Promise<Response> {
        const result = await fetchUtils.postAsync(utils.getBackendBaseUrl(), SUBSCRIBE_SUBSTACK_NEWSLETTER_ENDPOINT, {
            email,
            referrer: window.location.href,
        });
        return result;
    },
};