Skip to content

Commit

Permalink
Better environment and cli options configuration, README
Browse files Browse the repository at this point in the history
  • Loading branch information
owenkellogg committed Mar 31, 2024
1 parent 54a1f27 commit 7288ccb
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 22 deletions.
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,19 @@ Commands:

```
> walletbot start \
--seed-phrase="$SEED_PHRASE" \
--anypay-token=$ANYPAY_API_TOKEN
--seed-phrase="replace this with your twelve word seed phrase to start sending payments" \
--auth-token=replacewith-your-anypay-apiauthtoken
```

### Configuring with Environment Variables
In the same terminal shell tab or shell script first export the required environment variables,
then you can run walletbot without providing the equivalent command line arguments.

```
export walletbot_seed_phrase="replace this with your twelve word seed phrase to start sending payments"
export walletbot_auth_token=replacewith-your-anypay-apiauthtoken
walletbot start
```

## Running in Nodejs (Typescript)
Expand All @@ -51,8 +62,8 @@ Commands:
import { WalletBot } from '@anypay/walletbot'
const walletBot = new WalletBot({
seed_phrase: process.env.WALLET_BOT_BACKUP_SEED_PHRASE,
anypay_token: process.env.ANYPAY_ACCESS_TOKEN
seed_phrase: "replace this with your twelve word seed phrase to start sending payments",
anypay_token: "replacewith-your-anypay-apiauthtoken"
})
walletBot.start()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@anypay/walletbot",
"version": "1.7.0",
"version": "1.7.1",
"public": true,
"private": false,
"description": "Your Money-Sending Robot Friend",
Expand Down
4 changes: 2 additions & 2 deletions src/anypay.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

import { app } from 'anypay'

import config from './config'

const anypay = app(config.get('anypay_access_token'))
const anypay = app(config.get('walletbot_auth_token'))

export default anypay

5 changes: 0 additions & 5 deletions src/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ export async function listBalances(): Promise<Balance[]> {

const balances = await wallet.balances()

for (let balance of balances) {

log.info('balance', balance)
}

return balances

}
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export { Wallet, loadWallet }

export async function initWalletFromMnemonic(): Promise<Wallet> {

const mnemonic = config.get('wallet_bot_backup_seed_phrase')
const mnemonic = config.get('WALLETBOT_SEED_PHRASE')

if (!mnemonic) {

const error = new Error('no wallet_bot_backup_seed_phrase config variable set')
const error = new Error('no WALLETBOT_SEED_PHRASE config variable set')

log.error('config.env.invalid', error)

Expand Down
2 changes: 1 addition & 1 deletion src/invoices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function listUnpaid(): Promise<any[]> {

let { data } = await axios.get(url, {
auth: {
username: config.get('anypay_access_token'),
username: config.get('walletbot_auth_token'),
password: ''
}
})
Expand Down
12 changes: 6 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ const { version } = require('../package')
program
.name('walletbot')
.version(version)
.option('-s --seed-phrase <seed_phrase>', 'seed phrase for wallet bot')
.option('-t --anypay-token <anypay_token>', 'anypay token for wallet bot')
.option('-s --seed-phrase <seed_phrase>', '12-work seed phrase for wallet bot')
.option('-t --auth-token <auth_token>', 'anypay api auth token for wallet bot')

program
.command('start')
.action(async () => {

const options = program.opts();

console.log(options)
const AUTH_TOKEN = config.get("walletbot_auth_token");

const walletBot = new WalletBot({
seed_phrase: options.seedPhrase || config.get('wallet_bot_backup_seed_phrase'),
anypay_token: options.anypayToken || config.get('anypay_access_token'),
seed_phrase: options.seedPhrase || config.get('walletbot_seed_phrase'),
anypay_token: options.authToken || config.get('walletbot_auth_token'),
http_api_enabled: config.get('http_api_enabled'),
websocket_enabled: true,
websocket_url: config.get('websocket_url')
Expand All @@ -46,7 +46,7 @@ program

console.log(mnemonic)
})

program
.command('list-balances')
.action(async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/wallet_bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class WalletBot {

if (!this.options.anypay_token) {
log.error(`Please visit https://anypayx.com/dashboard/apps/wallet-bot to get your token`)
throw new Error('token not set')
throw new Error('walletbot_auth_token not set in environment variables')
}

const { wallets } = MnemonicWallet.init(this.options.seed_phrase)
Expand Down

0 comments on commit 7288ccb

Please sign in to comment.