Skip to content

Instantly share code, notes, and snippets.

View GrandSchtroumpf's full-sized avatar
🏠
Working from home

François GrandSchtroumpf

🏠
Working from home
  • Dapps Nation
  • Nantes
View GitHub Profile
@GrandSchtroumpf
GrandSchtroumpf / store-config.ts
Created September 21, 2018 07:47
Initial state in decorator
import { Store } from './store';
export type StoreConfigOptions = {
name: string;
idKey?: string;
initialState?: any
};
export interface Type<T> extends Function {
new (...args: any[]): T;
@GrandSchtroumpf
GrandSchtroumpf / store-config-v2.ts
Created September 21, 2018 09:29
Version 2 of Store-config for Akita
export type StoreConfigOptions = {
name: string;
idKey?: string;
initialState?: any
};
export interface Type<T> extends Function {
new (...args: any[]): T;
}
@GrandSchtroumpf
GrandSchtroumpf / webpack.config.js
Created October 8, 2018 18:47
The webpack config needed for a 3box-js project with angular
module.exports = {
node: {
crypto: true,
http: true,
https: true,
os: true,
vm: true,
stream: true,
fs: 'empty',
child_process: 'empty'
@GrandSchtroumpf
GrandSchtroumpf / app.component.ts
Created October 8, 2018 19:20
A component using the 3box.service.ts wrapper
import { WEB3 } from './web3';
import { Component, OnInit, Inject } from '@angular/core';
import { ThreeBox } from './3box/3box.service';
@Component({
selector: 'app-root',
template: '<p>3Box and Angular</p>'
})
export class AppComponent implements OnInit {
@GrandSchtroumpf
GrandSchtroumpf / 3box.ts
Created October 8, 2018 19:29
the interfaces of 3box
export interface Threebox {
public: KeyValueStore;
private: KeyValueStore;
close(): void;
logout(): void;
}
export interface KeyValueStore {
log(): Array<Object>;
get(key: string): string;
@GrandSchtroumpf
GrandSchtroumpf / 3box.service.ts
Last active October 8, 2018 19:30
A wrapper around 3box-js
import { Inject, Injectable } from '@angular/core';
import { WEB3 } from '../web3';
import { BoxOptions, GetProfileOptions, Threebox } from './3box';
import Web3 from 'web3';
import * as ThreeboxFactory from '3box';
import { BehaviorSubject } from 'rxjs';
@Injectable({ providedIn: 'root' })
export class ThreeBox {
@GrandSchtroumpf
GrandSchtroumpf / webpack.config.js
Last active October 15, 2018 09:04
A Webpack version for IPFS
module.exports = {
node: {
crypto: true,
path: true,
os: true,
stream: true,
buffer: true
}
}
@GrandSchtroumpf
GrandSchtroumpf / ipfs.ts
Created October 15, 2018 09:26
Angular Injection Token for IPFS
import { InjectionToken } from '@angular/core';
import ipfs from 'ipfs';
export const IPFS = new InjectionToken(
'The IPFS instance',
{
providedIn: 'root',
factory: () => new ipfs()
},
);
@GrandSchtroumpf
GrandSchtroumpf / app.component.ts
Created October 15, 2018 09:29
A simple component using the ipfs injection token
import { Component, Inject, OnInit } from '@angular/core';
import { IPFS } from './ipfs';
import {Buffer} from 'buffer';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
@GrandSchtroumpf
GrandSchtroumpf / ipfs.ts
Created October 15, 2018 09:39
A factory to init the ipfs node
// Before this function you should have the ipfs injection token
/**
* Wait for the IPFS node to be initialized when the app is launched
* @param node The Instance of the ipfs constructor
*/
export function initIPFS(node) {
return function() {
return new Promise((resolve, reject) => {
node.on('error', () => reject());
node.on('ready', () => resolve());