Skip to content

Commit

Permalink
Merge pull request #63 from airswap/fixes
Browse files Browse the repository at this point in the history
Fixes config overwrite and gas price handling
  • Loading branch information
Don Mosites authored Feb 23, 2020
2 parents f0d4515 + 1f703c0 commit 9bd1d6a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ USAGE
$ airswap account:delete
```

_See code: [src/commands/account/delete.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/account/delete.ts)_
_See code: [src/commands/account/delete.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/account/delete.ts)_

## `airswap account:export`

Expand All @@ -155,7 +155,7 @@ USAGE
$ airswap account:export
```

_See code: [src/commands/account/export.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/account/export.ts)_
_See code: [src/commands/account/export.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/account/export.ts)_

## `airswap account:generate`

Expand All @@ -166,7 +166,7 @@ USAGE
$ airswap account:generate
```

_See code: [src/commands/account/generate.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/account/generate.ts)_
_See code: [src/commands/account/generate.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/account/generate.ts)_

## `airswap account:import`

Expand All @@ -177,7 +177,7 @@ USAGE
$ airswap account:import
```

_See code: [src/commands/account/import.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/account/import.ts)_
_See code: [src/commands/account/import.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/account/import.ts)_

## `airswap balances`

Expand All @@ -188,7 +188,7 @@ USAGE
$ airswap balances
```

_See code: [src/commands/balances.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/balances.ts)_
_See code: [src/commands/balances.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/balances.ts)_

## `airswap gas`

Expand All @@ -199,7 +199,7 @@ USAGE
$ airswap gas
```

_See code: [src/commands/gas.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/gas.ts)_
_See code: [src/commands/gas.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/gas.ts)_

## `airswap help [COMMAND]`

Expand Down Expand Up @@ -227,7 +227,7 @@ USAGE
$ airswap indexer:enable
```

_See code: [src/commands/indexer/enable.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/indexer/enable.ts)_
_See code: [src/commands/indexer/enable.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/indexer/enable.ts)_

## `airswap indexer:get`

Expand All @@ -238,7 +238,7 @@ USAGE
$ airswap indexer:get
```

_See code: [src/commands/indexer/get.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/indexer/get.ts)_
_See code: [src/commands/indexer/get.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/indexer/get.ts)_

## `airswap indexer:new`

Expand All @@ -249,7 +249,7 @@ USAGE
$ airswap indexer:new
```

_See code: [src/commands/indexer/new.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/indexer/new.ts)_
_See code: [src/commands/indexer/new.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/indexer/new.ts)_

## `airswap indexer:set`

Expand All @@ -260,7 +260,7 @@ USAGE
$ airswap indexer:set
```

_See code: [src/commands/indexer/set.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/indexer/set.ts)_
_See code: [src/commands/indexer/set.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/indexer/set.ts)_

## `airswap indexer:unset`

Expand All @@ -271,7 +271,7 @@ USAGE
$ airswap indexer:unset
```

_See code: [src/commands/indexer/unset.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/indexer/unset.ts)_
_See code: [src/commands/indexer/unset.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/indexer/unset.ts)_

## `airswap ip`

Expand All @@ -282,7 +282,7 @@ USAGE
$ airswap ip
```

_See code: [src/commands/ip.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/ip.ts)_
_See code: [src/commands/ip.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/ip.ts)_

## `airswap metadata:add`

Expand All @@ -293,7 +293,7 @@ USAGE
$ airswap metadata:add
```

_See code: [src/commands/metadata/add.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/metadata/add.ts)_
_See code: [src/commands/metadata/add.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/metadata/add.ts)_

## `airswap metadata:delete`

Expand All @@ -304,7 +304,7 @@ USAGE
$ airswap metadata:delete
```

_See code: [src/commands/metadata/delete.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/metadata/delete.ts)_
_See code: [src/commands/metadata/delete.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/metadata/delete.ts)_

## `airswap metadata:lookup`

Expand All @@ -315,7 +315,7 @@ USAGE
$ airswap metadata:lookup
```

_See code: [src/commands/metadata/lookup.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/metadata/lookup.ts)_
_See code: [src/commands/metadata/lookup.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/metadata/lookup.ts)_

## `airswap metadata:update`

Expand All @@ -326,7 +326,7 @@ USAGE
$ airswap metadata:update
```

_See code: [src/commands/metadata/update.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/metadata/update.ts)_
_See code: [src/commands/metadata/update.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/metadata/update.ts)_

## `airswap network`

Expand All @@ -337,7 +337,7 @@ USAGE
$ airswap network
```

_See code: [src/commands/network.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/network.ts)_
_See code: [src/commands/network.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/network.ts)_

## `airswap order:best`

Expand All @@ -348,7 +348,7 @@ USAGE
$ airswap order:best
```

_See code: [src/commands/order/best.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/order/best.ts)_
_See code: [src/commands/order/best.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/order/best.ts)_

## `airswap order:get`

Expand All @@ -359,7 +359,7 @@ USAGE
$ airswap order:get
```

_See code: [src/commands/order/get.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/order/get.ts)_
_See code: [src/commands/order/get.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/order/get.ts)_

## `airswap quote:best`

Expand All @@ -370,7 +370,7 @@ USAGE
$ airswap quote:best
```

_See code: [src/commands/quote/best.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/quote/best.ts)_
_See code: [src/commands/quote/best.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/quote/best.ts)_

## `airswap quote:get`

Expand All @@ -381,7 +381,7 @@ USAGE
$ airswap quote:get
```

_See code: [src/commands/quote/get.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/quote/get.ts)_
_See code: [src/commands/quote/get.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/quote/get.ts)_

## `airswap quote:max`

Expand All @@ -392,7 +392,7 @@ USAGE
$ airswap quote:max
```

_See code: [src/commands/quote/max.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/quote/max.ts)_
_See code: [src/commands/quote/max.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/quote/max.ts)_

## `airswap token:approve`

Expand All @@ -403,7 +403,7 @@ USAGE
$ airswap token:approve
```

_See code: [src/commands/token/approve.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/token/approve.ts)_
_See code: [src/commands/token/approve.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/token/approve.ts)_

## `airswap token:transfer`

Expand All @@ -414,7 +414,7 @@ USAGE
$ airswap token:transfer
```

_See code: [src/commands/token/transfer.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/token/transfer.ts)_
_See code: [src/commands/token/transfer.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/token/transfer.ts)_

## `airswap weth:deposit`

Expand All @@ -425,7 +425,7 @@ USAGE
$ airswap weth:deposit
```

_See code: [src/commands/weth/deposit.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/weth/deposit.ts)_
_See code: [src/commands/weth/deposit.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/weth/deposit.ts)_

## `airswap weth:withdraw`

Expand All @@ -436,5 +436,5 @@ USAGE
$ airswap weth:withdraw
```

_See code: [src/commands/weth/withdraw.ts](https://github.com/airswap/airswap-cli/blob/v1.2.13/src/commands/weth/withdraw.ts)_
_See code: [src/commands/weth/withdraw.ts](https://github.com/airswap/airswap-cli/blob/v1.2.14/src/commands/weth/withdraw.ts)_
<!-- commandsstop -->
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "airswap",
"description": "Command Line Interface (CLI) for the AirSwap Network",
"version": "1.2.13",
"version": "1.2.14",
"repository": {
"type": "git",
"url": "https://github.com/airswap/airswap-cli"
Expand Down
4 changes: 2 additions & 2 deletions src/commands/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class Gas extends Command {
try {
const { fastest, fast, average } = await utils.getCurrentGasPrices()

const gasPrice = await utils.getGasPrice(this)
const gasPrice = await utils.getGasPrice(this, true)

this.log(`Current gas price: ${gasPrice}\n`)

Expand All @@ -26,7 +26,7 @@ export default class Gas extends Command {
},
})

await utils.setConfig(this, {
await utils.updateConfig(this, {
gasPrice: newGasPrice,
})

Expand Down
2 changes: 1 addition & 1 deletion src/commands/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default class Network extends Command {
if (!(newNetwork in constants.chainNames)) {
this.log(chalk.yellow(`\n${newNetwork} is not a supported chain.\n`))
} else {
await utils.setConfig(this, {
await utils.updateConfig(this, {
network: newNetwork,
})

Expand Down
16 changes: 11 additions & 5 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export function displayDescription(ctx: any, title: string, network?: number) {

export async function getConfig(ctx: any) {
const config = path.join(ctx.config.configDir, 'config.json')

if (!(await fs.pathExists(config))) {
await fs.outputJson(config, {
network: '4',
Expand All @@ -34,9 +33,13 @@ export async function getConfig(ctx: any) {
return await fs.readJson(config)
}

export async function setConfig(ctx: any, config: any) {
export async function updateConfig(ctx: any, config: any) {
const configPath = path.join(ctx.config.configDir, 'config.json')
await fs.outputJson(configPath, config)
const existingConfig = await getConfig(ctx)
await fs.outputJson(configPath, {
...existingConfig,
...config,
})
}

export async function getProvider(ctx: any) {
Expand Down Expand Up @@ -198,9 +201,12 @@ export async function getCurrentGasPrices() {
}
}

export async function getGasPrice(ctx: any) {
export async function getGasPrice(ctx: any, asGwei?: boolean) {
const { gasPrice } = await getConfig(ctx)
return gasPrice || constants.DEFAULT_GAS_PRICE
if (asGwei) {
return gasPrice || constants.DEFAULT_GAS_PRICE
}
return ethers.utils.parseUnits(gasPrice || constants.DEFAULT_GAS_PRICE, 'gwei')
}

export async function getProtocol(ctx: any) {
Expand Down

0 comments on commit 9bd1d6a

Please sign in to comment.