1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Add the token to the accounts that have it stored.

This commit is contained in:
Pedro Gutiérrez 2019-05-08 03:10:21 +02:00
parent b236cda7dd
commit b60e46a0b5
2 changed files with 28 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import { Instantiable, InstantiableConfig } from "../Instantiable.abstract"
*/
export default class Account extends Instantiable {
private password?: string
private token?: string
constructor(private id: string = "0x0", config?: InstantiableConfig) {
super()
@ -40,6 +41,22 @@ export default class Account extends Instantiable {
return this.password
}
/**
* Set account token.
* @param {string} token Token for account.
*/
public setToken(token: string): void {
this.token = token
}
/**
* Returns account token.
* @return {string} Account token.
*/
public getToken(): string {
return this.token
}
/**
* Balance of Ocean Token.
* @return {Promise<number>}

View File

@ -25,9 +25,18 @@ export class OceanAccounts extends Instantiable {
public async list(): Promise<Account[]> {
// retrieve eth accounts
const ethAccounts = await this.web3.eth.getAccounts()
const ethAccounts: string[] = await this.web3.eth.getAccounts()
return ethAccounts.map((address: string) => new Account(address, this.instanceConfig))
const accountPromises = ethAccounts
.map(address => new Account(address, this.instanceConfig))
.map(async account => {
const token = await this.ocean.auth.restore(account)
if (token) {
account.setToken(token)
}
return account
})
return Promise.all(accountPromises)
}
/**