This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
export const isAbortError = (error: any) => | |
typeof error === "object" && error !== null && error.name === "AbortError"; | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
export const isRpcError = ( | |
error: any | |
): error is { data: { message: string } } => | |
typeof error === "object" && | |
error !== null && |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { BaseContract } from "@ethersproject/contracts"; | |
import { useEffect, useState } from "react"; | |
const useChainId = (contract: BaseContract | undefined) => { | |
const [chainId, setChainId] = useState<number>(); | |
useEffect(() => { | |
const updateChainId = async (contract: BaseContract | undefined) => | |
setChainId(await contract?.signer.getChainId()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example of using the usePause hook to log the transaction hash and the gas used | |
const { pause, isLoading: isPausing } = usePause({ | |
onTransaction: response => | |
console.log( | |
"transaction: ", | |
response.hash | |
), | |
onSuccess: receipt => | |
console.log( | |
"gas used: ", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// based on: https://github.com/MetaMask/jazzicon | |
import React, { useState, useEffect } from "react"; | |
import MersenneTwister from "mersenne-twister"; | |
type RGB = { | |
r: number; | |
g: number; | |
b: number; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int Sum(List<int> source) | |
=> Sum(CollectionsMarshal.AsSpan(source)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static int Sum(List<int> source) | |
{ | |
var sum = 0; | |
for (var index = 0; index < source.Count; index++) | |
sum += source[index]; | |
return sum; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#nullable enable | |
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using System.Diagnostics.CodeAnalysis; | |
namespace NetFabric | |
{ | |
public class Deck<T> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Runtime.InteropServices; | |
namespace NetFabric | |
{ | |
public static class ShuffleExtensions | |
{ | |
public static void Shuffle<T>(this List<T> source) | |
=> Shuffle(source, new Random()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async ValueTask<int> CountAsync<TEnumerable, TEnumerator, TSource>(this TEnumerable source, CancellationToken cancellationToken = default) | |
where TEnumerable : IAsyncValueEnumerable<TSource, TEnumerator> | |
where TEnumerator : struct, IAsyncEnumerator<TSource> | |
{ | |
var counter = 0; | |
var enumerator = source.GetAsyncEnumerator(cancellationToken); | |
try | |
{ | |
checked | |
{ |