Skip to content

Instantly share code, notes, and snippets.

View pedrouid's full-sized avatar
🛠️
Building @WalletConnect

Pedro Gomes pedrouid

🛠️
Building @WalletConnect
View GitHub Profile
@pedrouid
pedrouid / getLocalIpAddress.js
Last active July 18, 2020 15:53
Get Local IP Address from Browser (inspired by net.ipcalf.com)
function getLocalIpAddress() {
return new Promise(function (resolve, reject) {
var RTCPeerConnection = window.RTCPeerConnection || window.webkitRTCPeerConnection || window.mozRTCPeerConnection;
if (RTCPeerConnection) {
var rtc = new RTCPeerConnection({iceServers: []});
if (1 || window.mozRTCPeerConnection) { // FF [and now Chrome!] needs a channel/stream to proceed
rtc.createDataChannel('', {reliable: false});
};
@pedrouid
pedrouid / walletconnect-sdk.js
Created June 15, 2020 16:01
WalletConnect SDK
import WalletConnect from "walletconnect";
// Create WalletConnect SDK instance
const wc = new WalletConnect();
// Connect session (triggers QR Code modal)
const connector = await wc.connect();
// Get your desired provider
@pedrouid
pedrouid / ethereumTokenInterfaces.md
Last active January 9, 2020 07:21
Ethereum Token Standard Interfaces (ERC-20 vs ERC-223 vs ERC-777)

ERC20 - Token Standard

https://github.com/ethereum/EIPs/blob/master/EIPS/eip-20.md

contract ERC20 {
   function totalSupply() constant returns (uint theTotalSupply);
   function balanceOf(address _owner) constant returns (uint balance);
   function transfer(address _to, uint _value) returns (bool success);
   function transferFrom(address _from, address _to, uint _value) returns (bool success);
   function approve(address _spender, uint _value) returns (bool success);
@pedrouid
pedrouid / recursive-parse.ts
Created December 8, 2019 14:46
Recursive Parse (BigNumber example)
const BigNumber = require("bignumber.js");
let test = {
initialState: {
amount: {
_hex: "0x4563918244f40000",
},
assetId: "0xeec918d74c746167564401103096D45BbD494B74",
coinTransfers: [
{
@pedrouid
pedrouid / recursive-parse.ts
Created December 8, 2019 14:46
Recursive Parse (BigNumber example)
const BigNumber = require("bignumber.js");
let test = {
initialState: {
amount: {
_hex: "0x4563918244f40000",
},
assetId: "0xeec918d74c746167564401103096D45BbD494B74",
coinTransfers: [
{
@pedrouid
pedrouid / migration.md
Last active September 15, 2019 12:27
Migrating Web3Connect from v1.0.0-beta.20 to v1.0.0-beta.22

Web3Connect

Migrating from v1.0.0-beta.20 to v1.0.0-beta.22

Note: We had to skip v1.0.0-beta.21 on NPM because of a test version that was published.

In this latest release (v1.0.0-beta.22), we've had to (once again) introduce breaking changes to allow Web3Connect to work with optional dependencies. When integrating Web3Connect you can choose each providers to support but unfortunately on the v1.0.0-beta.20 you were still required to install all of them as dependencies in your app even if they were disabled. However with the new release (v1.0.0-beta.22) we require dependencies to be injected to enable the providers you choose to support hence there are breaking changes in the library options.

Below I will describe the before and after of each integration type avaiable with Web3Connect.

React Button

@pedrouid
pedrouid / migration.md
Last active September 10, 2019 09:34
Migrating Web3Connect from v1.0.0-beta.19 to v1.0.0-beta.20

Web3Connect

Migrating from v1.0.0-beta.19 to v1.0.0-beta.20

In this last release, we've refactored the library considerably which includes breaking changes from the previous release. But you will be please to know that we reduced the bundle size from 3.91 mb to 314 kb!! That's a 92% bundle size decrease!!!!

However this comes with its own caveats. Check the two sections bellow for the changes made for Install, Options and Single Provider

Install

@pedrouid
pedrouid / 3box-thread.js
Created August 23, 2019 19:54
3Box Threads
// Creating/joining thread in space
const thread = await space.joinThread('orders')
// Others can join by same space and thread name or by thread address
const thread = await space.joinThreadByAddress('/orbitdb/zdpuAp5QpBKR4BBVTvqe3KXVcNgo4z8Rkp9C5eK38iuEZj3jq/3box.thread.pos_bufficorn.orders')
// Post new order in thread
await thread.post({order_id: '123', item_id: '456', amount: '0.0015'})
// Listen live for new thread posts
@pedrouid
pedrouid / 3box-auth.js
Created August 23, 2019 19:54
Auth with 3box
// Authenticate store owner
const box = Box.openBox(ethAddress, window.ethereum)
// App specific space for store owner
const space = await box.openSpace('pos_bufficorn')
// Add data/items
await space.public.set('store_settings', JSON.stringify({ name:'Bufficorn Cafe', description: 'Locally Roasted Coffee in Denver'}))
@pedrouid
pedrouid / index.ts
Created July 18, 2019 13:18
Redux Thunk Async Example
export const accountLogin = (username: string, password: string) => async (
dispatch: any,
getState: any
) => {
dispatch({ type: ACCOUNT_LOGIN_REQUEST });
try {
const session = await apiLogin(username, password)
dispatch({ type: ACCOUNT_LOGIN_SUCCESS, payload: session });