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:
parent
b236cda7dd
commit
b60e46a0b5
@ -8,6 +8,7 @@ import { Instantiable, InstantiableConfig } from "../Instantiable.abstract"
|
|||||||
*/
|
*/
|
||||||
export default class Account extends Instantiable {
|
export default class Account extends Instantiable {
|
||||||
private password?: string
|
private password?: string
|
||||||
|
private token?: string
|
||||||
|
|
||||||
constructor(private id: string = "0x0", config?: InstantiableConfig) {
|
constructor(private id: string = "0x0", config?: InstantiableConfig) {
|
||||||
super()
|
super()
|
||||||
@ -40,6 +41,22 @@ export default class Account extends Instantiable {
|
|||||||
return this.password
|
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.
|
* Balance of Ocean Token.
|
||||||
* @return {Promise<number>}
|
* @return {Promise<number>}
|
||||||
|
@ -25,9 +25,18 @@ export class OceanAccounts extends Instantiable {
|
|||||||
public async list(): Promise<Account[]> {
|
public async list(): Promise<Account[]> {
|
||||||
|
|
||||||
// retrieve eth accounts
|
// 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user