本文整理汇总了TypeScript中decentraland-commons.env类的典型用法代码示例。如果您正苦于以下问题:TypeScript env类的具体用法?TypeScript env怎么用?TypeScript env使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了env类的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()
}
}
示例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
}
示例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()
}
示例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 {
示例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}`, {})
}
示例6: loadEnv
export function loadEnv(envFilePath: string = '../src/.env') {
env.load({ path: resolvePath(envFilePath) })
}
示例7:
predicate: (_: any, action) =>
env.isDevelopment() || action.type.includes('Failure')
示例8: 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)
示例9: Assertion
import * as chai from 'chai'
import { env } from 'decentraland-commons'
import { omitProps } from './utils'
const Assertion = (chai as any).Assertion // necessary because @types/chai doesn't export chai.Assertion yet
chai.use(require('chai-as-promised'))
env.load({ path: './specs/.env' })
Assertion.addChainableMethod('equalRow', function(expectedRow: any) {
const omittedProps = ['created_at', 'updated_at']
if (!expectedRow.id) {
omittedProps.push('id')
}
const actualRow = omitProps(this._obj, omittedProps)
return new Assertion(expectedRow).to.deep.equal(actualRow)
})
Assertion.addChainableMethod('equalRows', function(expectedRows: any[]) {
const omittedProps = ['created_at', 'updated_at']
if (expectedRows.every(row => !row.id)) {
omittedProps.push('id')
}
const actualRows = this._obj.map(_obj => omitProps(_obj, omittedProps))
return new Assertion(expectedRows).to.deep.equal(actualRows)
示例10:
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 }