0.0.45 • Published 3 years ago

angular-web3-components v0.0.45

Weekly downloads
161
License
-
Repository
-
Last release
3 years ago

AngularWeb3Components

Angular Web3 components library

Installation

The package can be installed via npm:

npm i angular-web3-components

You'll need to import AngularWeb3ComponentsModule to your module:

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import {AngularWeb3ComponentsModule} from 'angular-web3-components';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    AngularWeb3ComponentsModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Recent transactions component

Component for storing and displaying recent transactions from Web3.

Usage

You'll need to provide AngularWeb3RecentTransactionsService to your root module:

import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import {AngularWeb3ComponentsModule} from 'angular-web3-components';
import {AngularWeb3RecentTransactionsService} from 'angular-web3-components';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    AngularWeb3ComponentsModule
  ],
  providers: [AngularWeb3RecentTransactionsService],
  bootstrap: [AppComponent]
})
export class AppModule { }

Then use component like below:

<ng-web3-recent-transactions [accountAddress]="accountAddress" 
                             [applicationName]="applicationName" 
                             [storageService]="storageService" 
                             [web3]="web3"></ng-web3-recent-transactions>

where

  • accountAddress - user account address, used for storage unique key.
  • applicationNames - your application name, used for storage unique key.
  • storageService - your storage service. Should implements IAngularWeb3StorageService model:
import {IAngularWeb3StorageService} from 'angular-web3-components'

export class myStorageService implements IAngularWeb3StorageService {
  
    get(key: string): any {
      // get from storage
    }
    
    set(key: string, value: any): boolean {
      // set to storage
    }
    
    remove(key: string): boolean {
      // remove from storage
    }
}
  • web3 - your web3 object.

In order save transactions, you need to call saveTransaction method of AngularWeb3RecentTransactionsService:

import { Component } from '@angular/core';
import {AngularWeb3RecentTransactionsService} from 'angular-web3-components';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponent {
  
  constructor(public recentTransactionsService: AngularWeb3RecentTransactionsService) { }

  public saveTransaction(name: string, hash: string, ): void {
    this.recentTransactionsService.saveTransaction(name, hash);
  }
}

where

  • name - transaction name
  • hash - transaction hash

In order to know when transaction completed or reverted - subscribe to transactionStatusChange property of AngularWeb3RecentTransactionsService, which emits IAngularWeb3Transaction object each time when particular transaction status has been changed from 'pending' to 'success' or 'fail':

import { Component, OnInit } from '@angular/core';
import {AngularWeb3RecentTransactionsService, IAngularWeb3Transaction} from 'angular-web3-components';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnInit {
  
  constructor(public recentTransactionsService: AngularWeb3RecentTransactionsService) { }

  ngOnInit() {
    this.recentTransactionsService.transactionStatusChange.subscribe((transaction: IAngularWeb3Transaction) => {
      // do something
    });
  }
}

Also you can subscribe to transactionsChange property of AngularWeb3RecentTransactionsService, which emits full array with transactions of IAngularWeb3Transaction type on any transaction change:

import { Component, OnInit } from '@angular/core';
import {AngularWeb3RecentTransactionsService, IAngularWeb3Transaction} from 'angular-web3-components';

@Component({
  selector: 'app-my-component',
  templateUrl: './my-component.component.html',
  styleUrls: ['./my-component.component.css']
})
export class MyComponent implements OnInit {
  
  constructor(public recentTransactionsService: AngularWeb3RecentTransactionsService) { }

  ngOnInit() {
    this.recentTransactionsService.transactionsChange.subscribe((transactions: IAngularWeb3Transaction[]) => {
      // do something
    });
  }
}

IAngularWeb3Transaction type is as follows:

export interface IAngularWeb3Transaction {
  name: string;
  hash: string;
  status: 'pending' | 'success' | 'fail';
}

where

  • name - transaction name
  • hash - transaction hash
  • status - transaction status, which can be 'pending', 'success' or 'fail'

##Compatibility

Angular 9 and newer

0.0.44

3 years ago

0.0.45

3 years ago

0.0.41

3 years ago

0.0.42

3 years ago

0.0.43

3 years ago

0.0.40

3 years ago

0.0.39

3 years ago

0.0.38

3 years ago

0.0.37

3 years ago

0.0.34

3 years ago

0.0.35

3 years ago

0.0.36

3 years ago

0.0.32

3 years ago

0.0.33

3 years ago

0.0.31

3 years ago

0.0.30

3 years ago

0.0.29

3 years ago

0.0.28

3 years ago

0.0.27

3 years ago

0.0.26

3 years ago

0.0.25

3 years ago

0.0.20

3 years ago

0.0.21

3 years ago

0.0.22

3 years ago

0.0.23

3 years ago

0.0.24

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.18

3 years ago

0.0.19

3 years ago

0.0.15

3 years ago

0.0.14

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.11

3 years ago

0.0.10

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago