当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript env.get方法代码示例

本文整理汇总了TypeScript中decentraland-commons.env.get方法的典型用法代码示例。如果您正苦于以下问题:TypeScript env.get方法的具体用法?TypeScript env.get怎么用?TypeScript env.get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在decentraland-commons.env的用法示例。


在下文中一共展示了env.get方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: main

export async function main() {
  log.info('Connecting database')
  await db.connect()

  const tokens = await Token.find<TokenAttributes>()

  for (const token of tokens) {
    if (DistrictToken.isValid(token)) continue

    const tokenContract = Object.create(new contracts.ERC20Token(token.address))
    tokenContract.getContractName = () => token.name
    tokenContracts[token.address] = tokenContract
  }

  try {
    log.info(`Connecting to Ethereum Node with ${tokens.map(t => t.name)}`)
    await eth.connect({
      contracts: Object.values(tokenContracts),
      provider: env.get('RPC_URL')
    })

    const delay = env.get('MONITOR_BALANCES_DELAY', '10000')
    log.info(`Using ${delay}ms as delay between updates`)
    await monitorBalances(Number(delay))
  } catch (error) {
    log.info('Whoops, something went wrong')
    log.info(error)

    process.exit()
  }
}
开发者ID:decentraland,项目名称:agora,代码行数:31,代码来源:monitorBalances.ts

示例2: migrate

export function migrate(
  commandArguments: string[],
  migrationsDir: string = __dirname
) {
  let CONNECTION_STRING = process.env.CONNECTION_STRING

  if (!CONNECTION_STRING) {
    loadEnv()

    CONNECTION_STRING = env.get('CONNECTION_STRING')
    if (!CONNECTION_STRING) {
      throw new Error(
        'Please set a CONNECTION_STRING env variable before running migrations'
      )
    }
  }

  const spawnArgs = [
    '--database-url-var',
    'CONNECTION_STRING',
    '--migration-file-language',
    'ts',
    '--migrations-dir',
    migrationsDir,
    '--ignore-pattern',
    '\\..*|.*migrate',
    ...commandArguments
  ]
  const child = spawn(resolvePath(__dirname + '/node-pg-migrate'), spawnArgs, {
    env: { ...process.env, CONNECTION_STRING }
  })

  console.log('Running command:')
  console.dir(`node-pg-migrate ${spawnArgs.join(' ')}`)

  child.on('error', function(error) {
    console.log(error.message)
  })

  child.stdout.on('data', function(data) {
    process.stdout.write(data.toString())
  })

  child.stderr.on('data', function(data) {
    process.stdout.write(data.toString())
  })

  return child
}
开发者ID:decentraland,项目名称:agora,代码行数:49,代码来源:migrate.ts

示例3: seed

async function seed() {
  const tokenAddress = env.get('MANA_TOKEN_CONTRACT_ADDRESS', '')

  console.log('Connecting database')
  await db.connect()

  console.log('Inserting tokens')
  await Promise.all([
    Token.create({
      address: tokenAddress.toLowerCase(),
      name: 'MANAToken',
      symbol: 'MANA'
    })
  ])

  console.log('Inserting account balances')
  await Promise.all([
    AccountBalance.create({
      address: '0x66788F71Bf33EcBd263a57E5F371cCDCaFfc519e',
      balance: '10',
      token_address: tokenAddress
    }),
    AccountBalance.create({
      address: '0x38b5ca83896C7C6Bf4C6178b7458cAAD5412A37A',
      balance: '25',
      token_address: tokenAddress
    }),
    AccountBalance.create({
      address: '0x1d9aa2025b67f0f21d1603ce521bda7869098f8a',
      balance: '15',
      token_address: tokenAddress
    })
  ])

  console.log('Inserting polls')
  await Promise.all([
    Poll.create({
      title: 'Should we support an auction model natively in the Marketplace?',
      balance: '50',
      submitter: '0x66788f71bf33ecbd263a57e5f371ccdcaffc519e',
      closes_at: '1537897526681',
      token_address: tokenAddress
    })
  ])
  const poll = (await Poll.find())[0]

  console.log('Inserting options')
  await Promise.all([
    Option.create({ value: 'YES', poll_id: poll.id }),
    Option.create({ value: 'NO', poll_id: poll.id })
  ])

  const options = await Option.find()

  console.log('Inserting votes')
  await Promise.all([
    Vote.create({
      account_address: '0x66788f71bf33ecbd263a57e5f371ccdcaffc519e',
      account_balance: '10',
      poll_id: poll.id,
      option_id: options[0].id,
      timestamp: Date.now(),
      message: 'signed1',
      signature: 'signature1'
    }),
    Vote.create({
      account_address: '0x38b5ca83896c7c6bf4c6178b7458caad5412a37a',
      account_balance: '25',
      poll_id: poll.id,
      option_id: options[1].id,
      timestamp: Date.now(),
      message: 'signed2',
      signature: 'signature2'
    }),
    Vote.create({
      account_address: '0x1d9aa2025b67f0f21d1603ce521bda7869098f8a',
      account_balance: '15',
      poll_id: poll.id,
      option_id: options[1].id,
      timestamp: Date.now(),
      message: 'signed3',
      signature: 'signature3'
    })
  ])

  process.exit()
}
开发者ID:decentraland,项目名称:agora,代码行数:87,代码来源:seed.ts

示例4: createWalletSaga

import {
  ConnectWalletSuccessAction,
  CONNECT_WALLET_SUCCESS
} from '@dapps/modules/wallet/actions'
import {
  COMPUTE_BALANCES_REQUEST,
  computeBalancesSuccess,
  computeBalancesFailure
} from 'modules/wallet/actions'
import { fetchAccountBalancesRequest } from 'modules/accountBalance/actions'
import { fetchTokensRequest } from 'modules/token/actions'
import { getContractTokens } from 'modules/token/selectors'
import { MANAToken } from 'contracts'

const baseWalletSaga = createWalletSaga({
  provider: env.get('REACT_APP_PROVIDER_URL'),
  contracts: [MANAToken],
  eth
})

export function* walletSaga() {
  yield all([baseWalletSaga(), walletBalanceSaga()])
}

function* walletBalanceSaga() {
  yield takeEvery(CONNECT_WALLET_SUCCESS, handleConnectWalletSuccess)
  yield takeEvery(COMPUTE_BALANCES_REQUEST, handleComputeBalancesRequest)
}

function* handleComputeBalancesRequest() {
  try {
开发者ID:decentraland,项目名称:agora,代码行数:31,代码来源:sagas.ts

示例5: fetchTokens

import { env } from 'decentraland-commons'
import { BaseAPI } from '@dapps/lib/api'
import { PollsRequestFilters } from 'modules/poll/types'

const URL = env.get('REACT_APP_API_URL', '')

export class API extends BaseAPI {
  fetchTokens() {
    return this.request('get', '/tokens', {})
  }

  fetchPolls(filters: PollsRequestFilters) {
    return this.request('get', '/polls', filters)
  }

  fetchPoll(id: string) {
    return this.request('get', `/polls/${id}`, {})
  }

  fetchPollOptions(id: string) {
    return this.request('get', `/polls/${id}/options`, {})
  }

  fetchPollVotes(id: string) {
    return this.request('get', `/polls/${id}/votes`, {})
  }

  fetchTranslations(locale: string) {
    return this.request('get', `/translations/${locale}`, {})
  }
开发者ID:decentraland,项目名称:agora,代码行数:30,代码来源:api.ts

示例6: createHistory

import { rootSaga } from './sagas'

const composeEnhancers =
  (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose

const history = createHistory()

const historyMiddleware = routerMiddleware(history)
const sagasMiddleware = createSagasMiddleware()
const loggerMiddleware = createLogger({
  collapsed: () => true,
  predicate: (_: any, action) =>
    env.isDevelopment() || action.type.includes('Failure')
})
const analyticsMiddleware = createAnalyticsMiddleware(
  env.get('REACT_APP_SEGMENT_API_KEY')
)
const { storageMiddleware, loadStorageMiddleware } = createStorageMiddleware({
  storageKey: env.get('REACT_APP_LOCAL_STORAGE_KEY', 'decentraland-agora')
})

const middleware = applyMiddleware(
  historyMiddleware,
  sagasMiddleware,
  loggerMiddleware,
  analyticsMiddleware,
  storageMiddleware
)
const enhancer = composeEnhancers(middleware)
const store = createStore(rootReducer, enhancer)
开发者ID:decentraland,项目名称:agora,代码行数:30,代码来源:store.ts

示例7:

import { env } from 'decentraland-commons'
import { contracts } from 'decentraland-eth'
const MANAToken = new contracts.MANAToken(
  env.get('REACT_APP_MANA_TOKEN_CONTRACT_ADDRESS')
)
export { MANAToken }
开发者ID:decentraland,项目名称:agora,代码行数:6,代码来源:contracts.ts

示例8: express

import * as bodyParser from 'body-parser'
import * as express from 'express'
import { env } from 'decentraland-commons'
import { AccountBalanceRouter } from './AccountBalance'
import { OptionRouter } from './Option'
import { PollRouter } from './Poll'
import { ReceiptRouter } from './Receipt'
import { VoteRouter } from './Vote'
import { TokenRouter } from './Token'
import { TranslationRouter } from './Translation'
import { db } from './database'

env.load()

const SERVER_PORT = env.get('SERVER_PORT', 5000)

const app = express()

app.use(bodyParser.urlencoded({ extended: false, limit: '2mb' }))
app.use(bodyParser.json())

if (env.isDevelopment()) {
  app.use(function(_, res, next) {
    res.setHeader('Access-Control-Allow-Origin', '*')
    res.setHeader('Access-Control-Request-Method', '*')
    res.setHeader(
      'Access-Control-Allow-Methods',
      'OPTIONS, GET, POST, PUT, DELETE'
    )
    res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
开发者ID:decentraland,项目名称:agora,代码行数:30,代码来源:server.ts

示例9: translate

  return text[0].toUpperCase() + text.slice(1)
}

async function translate(lang: string, text: string): Promise<string> {
  /* Result example:
  [
    [
      [ "Debes {sign_in_link} para acceder a esta pรกgina", "You need to {sign_in_link} to access this page", null, null, 3 ]
    ],
    null,
    "en"
  ] */

  const result = await axios.get(
    `https://translate.googleapis.com/translate_a/single?client=gtx&sl=en&tl=${lang}&dt=t&q=${encodeURIComponent(
      text
    )}`
  )
  const translation: string = result.data[0][0][0]
  return translation
}

if (require.main === module) {
  loadEnv()

  BATCH_SIZE = parseInt(env.get('BATCH_SIZE', '10'), 10)
  log.info(`Using ${BATCH_SIZE} as batch size, configurable via BATCH_SIZE`)

  main().catch(error => console.error(error))
}
开发者ID:decentraland,项目名称:agora,代码行数:30,代码来源:translate.ts

示例10: async

database.connect = async () => {
  const CONNECTION_STRING = env.get('CONNECTION_STRING', undefined)
  this.client = await pg.connect(CONNECTION_STRING)
  return this
}
开发者ID:decentraland,项目名称:agora,代码行数:5,代码来源:database.ts


注:本文中的decentraland-commons.env.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。