Skip to content

Instantly share code, notes, and snippets.

@mikekoro
mikekoro / gist:c061b0285eda15d3dbed970908f60686
Last active October 10, 2024 19:05
Get ETH and SX prices from Uniswap v3
const rpcUrl = CHAIN_CONFIGS[1].rpcUrls[0];
const provider = new providers.StaticJsonRpcProvider(rpcUrl, 1);
const UniswapV3Pool = await import('../../config/abi/UniswapV3Pool.json');
const sxUsdcPoolAddress = "0xCb3b931E1e02C26399aCc651bFD9c8c4385EECd0";
const ethUsdcPoolAddress = "0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8";
const sxUsdcPoolContract = new Contract(sxUsdcPoolAddress, UniswapV3Pool.abi, provider);
const ethUsdcPoolContract = new Contract(ethUsdcPoolAddress, UniswapV3Pool.abi, provider);
import Web3 from 'web3';
export const getMetamask = (windowObject) => {
if(!windowObject.web3) {
return false
}
return windowObject.web3;
}
@mikekoro
mikekoro / Classes.js
Created August 4, 2020 20:32 — forked from gaearon/Classes.js
Beneath Classes: Prototypes
class Spiderman {
lookOut() {
alert('My Spider-Sense is tingling.');
}
}
let miles = new Spiderman();
miles.lookOut();
@mikekoro
mikekoro / helloWorld.js
Created August 4, 2020 20:17
Testing some stuff
import axios from 'axios';
/**
* Pull public gists from a Github user by their username
* @param {string} username Github username
*/
export const getGistsByUsername = async (username) => {
try {
let response = await axios({
// useSockets.js
import React, {
useState
} from 'react';
import io from 'socket.io-client';
export default function useSocket() {
const [Socket, setSocket] = useState(null);
const RandomNumberGenerator = () => {
const [number, setNumber] = useState(Math.random());
const regenerate = () => {
setNumber(Math.random());
}
const RandomNumber = () => {
return number;
}
return { regenerate, RandomNumber };
import React from 'react';
import { act, renderHook } from '@testing-library/react-hooks'; // Don't forget to install this package
import { useValue } from "./useValue";
it("Custom hook hooks:)", () => {
const { result } = renderHook(useValue);
act(() => {
result.current.assignValue('Hello World');
});
expect(result.current.value).toBe('Hello World');
// LoginPage.js
import React from 'react';
import { LoginForm } from 'LoginForm';
import { useValue } from 'useValue';
export default function LoginPage() {
const { value, assignValue } = useValue(false); // Calling our custom hook; false is the initial value this time around
import React from 'react';
import { LoginForm } from 'LoginForm';
import { useValue } from 'useValue';
export default function LoginPage() {
const { value, assignValue } = useValue(false); // Calling our custom hook; false is the initial value this time around
function handleSubmit() {
assignValue(true);
// LoginForm.js
import React from 'react';
import { useValue } from './useValue';
export function LoginForm({ handleSubmit }) {
const { value, assignValue } = useValue(''); // empty string is the initial value;
function handleChange(e) {