Skip to content

Commit

Permalink
fix: minor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Feb 11, 2022
1 parent df5cbc8 commit 03f172b
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 26 deletions.
11 changes: 11 additions & 0 deletions packages/ui-common/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.0.27](https://github.com/InjectiveLabs/injective-ts/compare/@injectivelabs/ui-common@0.0.26...@injectivelabs/ui-common@0.0.27) (2022-02-11)


### Bug Fixes

* minor stuff ([6cdd4ae](https://github.com/InjectiveLabs/injective-ts/commit/6cdd4aef2d3dadc04e8adfb8898c61ca22fb7d7e))





## [0.0.26](https://github.com/InjectiveLabs/injective-ts/compare/@injectivelabs/ui-common@0.0.25...@injectivelabs/ui-common@0.0.26) (2022-02-10)


Expand Down
2 changes: 1 addition & 1 deletion packages/ui-common/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@injectivelabs/ui-common",
"description": "Reusable Vue Components, Vuex Store Modules, Composables, and more",
"version": "0.0.26",
"version": "0.0.27",
"license": "MIT",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
8 changes: 7 additions & 1 deletion packages/ui-common/src/BaseActionService.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { Web3Strategy } from '@injectivelabs/web3-strategy'
import { getUrlEndpointForNetwork } from '@injectivelabs/networks'
import { MetricsProvider } from './providers/MetricsProvider'
import { TxProvider } from './providers/TxProvider'
import { ServiceOptions } from './types'
import { ServiceOptions, ServiceOptionsEndpoints } from './types'

export abstract class BaseActionService {
protected options: ServiceOptions

protected endpoints: ServiceOptionsEndpoints

protected metricsProvider: MetricsProvider | undefined

protected txProvider: TxProvider
Expand All @@ -14,6 +17,8 @@ export abstract class BaseActionService {

constructor(options: ServiceOptions, web3Strategy: Web3Strategy) {
this.options = options
this.endpoints =
options.endpoints || getUrlEndpointForNetwork(options.network)

if (options.metrics) {
this.metricsProvider = new MetricsProvider(options.metrics)
Expand All @@ -22,6 +27,7 @@ export abstract class BaseActionService {
this.web3Strategy = web3Strategy
this.txProvider = new TxProvider({
...options,
endpoints: this.endpoints,
web3Strategy: this.web3Strategy,
metricsProvider: this.metricsProvider,
})
Expand Down
7 changes: 6 additions & 1 deletion packages/ui-common/src/BaseService.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { getUrlEndpointForNetwork } from '@injectivelabs/networks'
import { MetricsProvider } from './providers/MetricsProvider'
import { ServiceOptions } from './types'
import { ServiceOptions, ServiceOptionsEndpoints } from './types'

export abstract class BaseService {
protected options: ServiceOptions

protected endpoints: ServiceOptionsEndpoints

protected metricsProvider: MetricsProvider | undefined

constructor(options: ServiceOptions) {
this.options = options
this.endpoints =
options.endpoints || getUrlEndpointForNetwork(options.network)

if (options.metrics) {
this.metricsProvider = new MetricsProvider(options.metrics)
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-common/src/bank/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class BankService extends BaseService {

constructor(options: ServiceOptions) {
super(options)
this.consumer = new BankConsumer(options.endpoints.sentryGrpcApi)
this.consumer = new BankConsumer(this.endpoints.sentryGrpcApi)
}

async fetchBalances(injectiveAddress: string) {
Expand Down
9 changes: 6 additions & 3 deletions packages/ui-common/src/bridge/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { subHours, format } from 'date-fns'
import {
computeLatestTransactions,
getLatestSelectedTransaction,
getPeggoGraphQlEndpoint,
} from './utils'
import { ExchangeMetrics, AccountMetrics } from '../types/metrics'
import { ApolloConsumer } from './gql/client'
Expand All @@ -17,10 +18,12 @@ export class BridgeService extends BaseService {

protected apolloConsumer: ApolloConsumer

constructor(options: ServiceOptions, peggyGraphQlEndpoint: string) {
constructor(options: ServiceOptions) {
super(options)
this.consumer = new BridgeTransactionConsumer(options.endpoints.exchangeApi)
this.apolloConsumer = new ApolloConsumer(peggyGraphQlEndpoint)
this.consumer = new BridgeTransactionConsumer(this.endpoints.exchangeApi)
this.apolloConsumer = new ApolloConsumer(
getPeggoGraphQlEndpoint(options.network),
)
}

static computeLatestTransactions = computeLatestTransactions
Expand Down
27 changes: 27 additions & 0 deletions packages/ui-common/src/bridge/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BridgingNetwork,
MintScanExplorerUrl,
} from './types'
import { PEGGY_GRAPH_URL, PEGGY_TESTNET_GRAPH_URL } from '../constants'

const sameTxHash = (txHashOne: string, txHashTwo: string) =>
txHashOne &&
Expand Down Expand Up @@ -173,6 +174,32 @@ export const getTerraExplorerUrl = (network: Network): string => {
}
}

export const getPeggoGraphQlEndpoint = (network: Network): string => {
if (
[
Network.Mainnet,
Network.MainnetK8s,
Network.Public,
Network.MainnetOld,
Network.MainnetStaging,
Network.Staging,
].includes(network)
) {
return PEGGY_GRAPH_URL
}

if ([Network.Testnet, Network.TestnetK8s].includes(network)) {
return PEGGY_TESTNET_GRAPH_URL
}

// TODO
if ([Network.Devnet].includes(network)) {
return PEGGY_TESTNET_GRAPH_URL
}

return ''
}

export const computeLatestTransactions = ({
latestTransactions,
peggoUserDeposits,
Expand Down
12 changes: 12 additions & 0 deletions packages/ui-common/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
export const INJ_DENOM = 'inj'
export const INJECTIVE_DENOM = 'inj'
export const INJ_COIN_GECKO_ID = 'injective-protocol'
export const BITCOIN_GECKO_ID = 'bitcoin'

export const GAS_LIMIT_MULTIPLIER = 1.2
export const ZERO: BigNumber = new BigNumber(0)
Expand All @@ -29,3 +30,14 @@ export const DEFAULT_GAS_PRICE = new BigNumber(6).times(GWEI_IN_WEI)

export const BIG_NUMBER_ROUND_DOWN_MODE = BigNumberInBase.ROUND_DOWN
export const BIG_NUMBER_ROUND_UP_MODE = BigNumberInBase.ROUND_UP

export const INJ_FEE_BUFFER = 0.01
export const BRIDGE_FEE_IN_USD = 10

// eslint-disable-next-line prefer-regex-literals
export const NUMBER_REGEX = new RegExp(/^-?(0|[1-9]\d*)?(\.\d+)?$/)

export const PEGGY_GRAPH_URL =
'https://api.thegraph.com/subgraphs/name/injectivelabs/injective-peggo-mainnet'
export const PEGGY_TESTNET_GRAPH_URL =
'https://api.thegraph.com/subgraphs/name/injectivelabs/injective-peggo-kovan'
8 changes: 3 additions & 5 deletions packages/ui-common/src/derivative/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@ export class DerivativeService extends BaseService {

constructor(options: ServiceOptions) {
super(options)
this.consumer = new DerivativeMarketConsumer(
options.endpoints.sentryGrpcApi,
)
this.consumer = new DerivativeMarketConsumer(this.endpoints.exchangeApi)
this.chronosConsumer = new DerivativeMarketChronosConsumer(
`${options.endpoints.exchangeApi}/api`,
`${this.endpoints.exchangeApi}/api`,
)
this.oracleConsumer = new OracleConsumer(options.endpoints.exchangeApi)
this.oracleConsumer = new OracleConsumer(this.endpoints.exchangeApi)
}

async fetchMarkets(): Promise<UiBaseDerivativeMarket[]> {
Expand Down
6 changes: 3 additions & 3 deletions packages/ui-common/src/spot/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export class SpotService extends BaseService {

constructor(options: ServiceOptions) {
super(options)
this.consumer = new SpotMarketConsumer(options.endpoints.sentryGrpcApi)
this.consumer = new SpotMarketConsumer(this.endpoints.exchangeApi)
this.chronosConsumer = new SpotMarketChronosConsumer(
`${options.endpoints.exchangeApi}/api`,
`${this.endpoints.exchangeApi}/api`,
)
this.oracleConsumer = new OracleConsumer(options.endpoints.exchangeApi)
this.oracleConsumer = new OracleConsumer(this.endpoints.exchangeApi)
}

async fetchMarkets(): Promise<UiBaseSpotMarket[]> {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui-common/src/subaccount/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class SubaccountService extends BaseService {

constructor(options: ServiceOptions) {
super(options)
this.consumer = new SubaccountConsumer(options.endpoints.sentryGrpcApi)
this.consumer = new SubaccountConsumer(this.endpoints.exchangeApi)
}

async fetchSubaccounts(address: string): Promise<string[]> {
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-common/src/token/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class TokenService extends BaseService {

constructor(options: ServiceOptions) {
super(options)
this.ibcConsumer = new IBCConsumer(options.endpoints.sentryGrpcApi)
this.erc20TokenMeta = Erc20TokenMetaFactory.make(options.network)
this.ibcConsumer = new IBCConsumer(this.endpoints.sentryGrpcApi)
this.erc20TokenMeta = Erc20TokenMetaFactory.make(this.options.network)
}

async fetchDenomTrace(denom: string) {
Expand Down
10 changes: 7 additions & 3 deletions packages/ui-common/src/token/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ export const tokenMetaToToken = (
if (tokenMeta.logo.startsWith('http')) {
icon = tokenMeta.logo
} else if (tokenMeta.logo) {
icon = tokenMeta.logo
} else if (!tokenMeta.logo) {
path.join('/', 'vendor', '@injectivelabs', 'token-metadata', tokenMeta.logo)
icon = path.join(
'/',
'vendor',
'@injectivelabs',
'token-metadata',
tokenMeta.logo,
)
} else {
icon = ''
}
Expand Down
5 changes: 5 additions & 0 deletions packages/ui-common/src/token/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export interface BankBalanceWithTokenMetaDataAndBalanceInBase {
token: TokenWithBalance
}

export interface BankBalanceWithTokenMetaDataAndBalanceWithUsdBalance
extends BankBalanceWithTokenMetaDataAndBalance {
balanceInUsd: BigNumberInBase
}

export interface IbcBankBalanceWithTokenMetaData
extends BankBalanceWithTokenMetaData {
baseDenom: string
Expand Down
5 changes: 5 additions & 0 deletions packages/ui-common/src/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,8 @@ export interface UiOrderbookPriceLevel {
aggregatePrices?: string[]
aggregatedPrice?: string
}

export interface UiOrderbookSummary {
quantity: BigNumberInBase
total: BigNumberInBase
}
12 changes: 7 additions & 5 deletions packages/ui-common/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export * from './cosmos'
export * from './common'
export * from './peggy'

export interface ServiceOptionsEndpoints {
exchangeApi: string
sentryGrpcApi: string
sentryHttpApi: string
}

export interface ServiceOptions {
chainId: ChainId
network: Network
Expand All @@ -15,11 +21,7 @@ export interface ServiceOptions {
region: string
}
| undefined
endpoints: {
exchangeApi: string
sentryGrpcApi: string
sentryHttpApi: string
}
endpoints?: ServiceOptionsEndpoints
}

export interface ServiceActionOptions {
Expand Down

0 comments on commit 03f172b

Please sign in to comment.