Skip to content

Commit

Permalink
Fix toolkit providers
Browse files Browse the repository at this point in the history
  • Loading branch information
maxima-net committed Aug 11, 2022
1 parent b2e3686 commit c26c364
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Web3EthereumSigner } from '../index';

export class Web3BlockchainToolkitProvider implements BlockchainToolkitProvider {
readonly toolkitId = 'web3';

protected readonlyToolkit: Web3 | undefined;
protected toolkit: Web3 | undefined;

Expand All @@ -32,7 +32,7 @@ export class Web3BlockchainToolkitProvider implements BlockchainToolkitProvider
if (!(signer instanceof Web3EthereumSigner))
return false;

this.readonlyToolkit = new Web3(signer.provider);
this.toolkit = new Web3(signer.web3.currentProvider);

return true;
}
Expand All @@ -41,7 +41,7 @@ export class Web3BlockchainToolkitProvider implements BlockchainToolkitProvider
if (!(signer instanceof Web3EthereumSigner))
return false;

this.readonlyToolkit = undefined;
this.toolkit = undefined;

return true;
}
Expand Down
12 changes: 4 additions & 8 deletions src/ethereum/signers/web3EthereumSigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ export class Web3EthereumSigner implements Signer {
constructor(
readonly atomexNetwork: AtomexNetwork,
readonly atomexContext: AtomexContext,
readonly provider: Web3['currentProvider']
readonly web3: Web3
) { }

static bind(atomex: Atomex, provider: Web3['currentProvider']): void {
const signer = new Web3EthereumSigner(atomex.atomexNetwork, atomex.atomexContext, provider);
static bind(atomex: Atomex, web3: Web3): void {
const signer = new Web3EthereumSigner(atomex.atomexNetwork, atomex.atomexContext, web3);
atomex.addSigner(signer);
}

async getAddress(): Promise<string> {
const web3 = await this.atomexContext.providers.blockchainProvider.getReadonlyToolkit(this.blockchain, 'web3') as Web3 | undefined;
if (!web3)
throw new Error('readonly web3 toolkit is unavailable');

const accounts = await web3.eth.getAccounts();
const accounts = await this.web3.eth.getAccounts();
const address = accounts[0];
if (!address)
throw new Error('Address is unavailable');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class TezosBlockchainToolkitProvider implements BlockchainToolkitProvider
if (!walletProvider)
return false;

this.readonlyToolkit = undefined;
this.toolkit = undefined;

return true;
}
Expand Down

0 comments on commit c26c364

Please sign in to comment.