Skip to content

Commit

Permalink
Sync from main to dev (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrwbabylonlab authored Jul 31, 2024
2 parents 2ce7406 + 58062aa commit 9851b5a
Show file tree
Hide file tree
Showing 33 changed files with 445 additions and 149 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
NEXT_PUBLIC_MEMPOOL_API=https://babylon.mempool.space
NEXT_PUBLIC_API_URL=https://staking-api.staging.babylonchain.io
NEXT_PUBLIC_API_URL=https://staking-api.testnet.babylonchain.io
NEXT_PUBLIC_NETWORK=signet
NEXT_PUBLIC_DISPLAY_TESTING_MESSAGES=true
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.

Parameters

Licensor: Babylonchain, Inc.
Licensor: Babylon Labs, Ltd.

Licensed Work: simple-staking
The Licensed Work is (c) 2024 Babylonchain, Inc.
The Licensed Work is (c) 2024 Babylon Labs, Ltd.

Additional Use Grant: None.

Expand Down
56 changes: 40 additions & 16 deletions docs/WalletIntegration.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ export interface UTXO {
scriptPubKey: string;
}

export interface Inscription {
// output of the inscription in the format of `txid:vout`
output: string;
export interface InscriptionIdentifier {
// hash of transaction that holds the ordinals/brc-2-/runes etc in the UTXO
txid: string;
// index of the output in the transaction
vout: number;
}

// supported networks
Expand Down Expand Up @@ -342,25 +344,47 @@ export class OKXWallet extends WalletProvider {
return await getTipHeight();
};

// Inscriptions(Ordinal/Runes/BRC-20 etc)
getInscriptions = async (): Promise<Inscription[]> => {
getInscriptions = async (): Promise<InscriptionIdentifier[]> => {
if (!this.okxWalletInfo) {
throw new Error("OKX Wallet not connected");
}
const inscriptions: Inscription[] = [];
// max num of iterations to prevent infinite loop
const MAX_ITERATIONS = 100;
// Fetch inscriptions in batches of 100
const limit = 100;
const inscriptionIdentifiers: InscriptionIdentifier[] = [];
let cursor = 0;
while (true) {
const { list } = await this.bitcoinNetworkProvider.getInscriptions(
cursor,
DEFAULT_INSCRIPTION_LIMIT,
);
inscriptions.push(...list);
if (list.length < DEFAULT_INSCRIPTION_LIMIT) {
break;
let iterations = 0;
try {
while (iterations < MAX_ITERATIONS) {
const { list } = await this.bitcoinNetworkProvider.getInscriptions(
cursor,
limit,
);
const identifiers = list.map((i: { output: string }) => {
const [txid, vout] = i.output.split(":");
return {
txid,
vout,
};
});
inscriptionIdentifiers.push(...identifiers);
if (list.length < limit) {
break;
}
cursor += limit;
iterations++;
if (iterations >= MAX_ITERATIONS) {
throw new Error(
"Exceeded maximum iterations when fetching inscriptions",
);
}
}
cursor += DEFAULT_INSCRIPTION_LIMIT;
} catch (error) {
throw new Error("Failed to get inscriptions from OKX Wallet");
}
return inscriptions;

return inscriptionIdentifiers;
};
}
```
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-staking",
"version": "0.2.20",
"version": "0.2.23",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -10,8 +10,8 @@
"format": "prettier --check .",
"format:fix": "prettier --write .",
"clean": "rm -r node_modules",
"build-docker": "docker build -t babylonchain/simple-staking .",
"clean-docker": "docker rmi babylonchain/simple-staking 2>/dev/null; true",
"build-docker": "docker build -t babylonlabs/simple-staking .",
"clean-docker": "docker rmi babylonlabs/simple-staking 2>/dev/null; true",
"prepare": "husky",
"sort-imports": "eslint --fix .",
"test": "jest",
Expand Down
8 changes: 8 additions & 0 deletions src/app/api/error/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { isAxiosError } from "axios";

export const isAxiosError451 = (error: any): boolean => {
return (
isAxiosError(error) &&
(error.response?.status === 451 || error.request.status === 451)
);
};
12 changes: 12 additions & 0 deletions src/app/api/healthCheckClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import axios from "axios";

interface HealthCheckResponse {
data: string;
}

export const fetchHealthCheck = async (): Promise<HealthCheckResponse> => {
const response = await axios.get(
`${process.env.NEXT_PUBLIC_API_URL}/healthcheck`,
);
return response.data;
};
45 changes: 37 additions & 8 deletions src/app/components/Connect/ConnectSmall.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { useRef, useState } from "react";
import { AiOutlineInfoCircle } from "react-icons/ai";
import { FaBitcoin } from "react-icons/fa";
import { IoMdClose } from "react-icons/io";
import { PiWalletBold } from "react-icons/pi";
import { Tooltip } from "react-tooltip";
import { useOnClickOutside } from "usehooks-ts";

import { useHealthCheck } from "@/app/hooks/useHealthCheck";
import { getNetworkConfig } from "@/config/network.config";
import { satoshiToBtc } from "@/utils/btcConversions";
import { maxDecimals } from "@/utils/maxDecimals";
Expand Down Expand Up @@ -34,6 +37,27 @@ export const ConnectSmall: React.FC<ConnectSmallProps> = ({
useOnClickOutside(ref, handleClickOutside);

const { coinName, networkName } = getNetworkConfig();
const { isApiNormal, isGeoBlocked, apiMessage } = useHealthCheck();

// Renders the Tooltip describing the reason
// why the user might not be able to connect the wallet
const renderApiNotAvailableTooltip = () => {
if (!isGeoBlocked && isApiNormal) return null;

return (
<>
<span
className="cursor-pointer text-xs"
data-tooltip-id="tooltip-connect"
data-tooltip-content={apiMessage}
data-tooltip-place="bottom"
>
<AiOutlineInfoCircle />
</span>
<Tooltip id="tooltip-connect" />
</>
);
};

return address ? (
<div className="relative mr-[-10px] text-sm hidden md:flex" ref={ref}>
Expand Down Expand Up @@ -92,13 +116,18 @@ export const ConnectSmall: React.FC<ConnectSmallProps> = ({
)}
</div>
) : (
<button
className="btn-primary btn h-[2.5rem] min-h-[2.5rem] rounded-full px-2 text-white md:rounded-lg"
onClick={onConnect}
disabled={!!address}
>
<PiWalletBold size={20} className="flex md:hidden" />
<span className="hidden md:flex">Connect to {networkName} network</span>
</button>
<div className="flex items-center gap-1">
<button
className="btn-primary btn h-[2.5rem] min-h-[2.5rem] rounded-full px-2 text-white md:rounded-lg"
onClick={onConnect}
// Disable the button if the user is already connected
// or: API is not available, geo-blocked, or has an error
disabled={!!address || !isApiNormal}
>
<PiWalletBold size={20} className="flex md:hidden" />
<span className="hidden md:flex">Connect to {networkName} network</span>
</button>
{!isApiNormal && renderApiNotAvailableTooltip()}
</div>
);
};
2 changes: 1 addition & 1 deletion src/app/components/FAQ/data/questions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const questions = (coinName: string): Question[] => {
},
{
title: "Are there any other ways to stake?",
content: `<p>Hands-on stakers can operate the <a href="https://github.com/babylonchain/btc-staker/blob/dev/docs/create-phase1-staking.md" target="_blank" rel="noopener noreferrer" class="text-primary"><u>btc-staker CLI program</u></a> that allows for the creation of ${coinName} staking transactions from the CLI.</p>
content: `<p>Hands-on stakers can operate the <a href="https://github.com/babylonlabs-io/btc-staker/blob/dev/docs/create-phase1-staking.md" target="_blank" rel="noopener noreferrer" class="text-primary"><u>btc-staker CLI program</u></a> that allows for the creation of ${coinName} staking transactions from the CLI.</p>
`,
},
{
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const iconLinks = [
},
{
name: "GitHub",
url: "https://github.com/babylonchain",
url: "https://github.com/babylonlabs-io",
Icon: BsGithub,
},
{
Expand All @@ -50,7 +50,7 @@ const iconLinks = [
},
{
name: "Email",
url: "mailto:contact@babylonchain.io",
url: "mailto:contact@babylonlabs.io",
Icon: MdAlternateEmail,
},
{
Expand Down
52 changes: 28 additions & 24 deletions src/app/components/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { shouldDisplayTestingMsg } from "@/config";

import { ConnectSmall } from "../Connect/ConnectSmall";
import { ConnectedSmall } from "../Connect/ConnectedSmall";
import { TestingInfo } from "../TestingInfo/TestingInfo";
Expand All @@ -21,36 +23,38 @@ export const Header: React.FC<HeaderProps> = ({
return (
<nav>
<div className="bg-base-300 shadow-sm">
<div className="container mx-auto flex-col">
<div className="w-full flex items-center justify-between gap-4 p-6 pb-4 md:pb-6">
<Logo />
<div className="flex flex-1">
<div className="container mx-auto flex w-full items-center justify-between gap-4 p-6 pb-4 md:pb-6">
<Logo />
<div className="flex flex-1">
{shouldDisplayTestingMsg() && (
<div className="hidden flex-1 xl:flex">
<TestingInfo />
</div>
</div>
<ConnectSmall
onConnect={onConnect}
address={address}
btcWalletBalanceSat={btcWalletBalanceSat}
onDisconnect={onDisconnect}
/>
<ThemeToggle />
</div>
<div
className={`container mx-auto flex w-full items-center gap-4 md:hidden md:p-0 ${address ? "justify-end p-6 pt-0" : ""}`}
>
<ConnectedSmall
address={address}
btcWalletBalanceSat={btcWalletBalanceSat}
onDisconnect={onDisconnect}
/>
)}
</div>
<ConnectSmall
onConnect={onConnect}
address={address}
btcWalletBalanceSat={btcWalletBalanceSat}
onDisconnect={onDisconnect}
/>
<ThemeToggle />
</div>
<div
className={`${address && "justify-end p-6 pt-0"}container mx-auto flex w-full items-center gap-4 md:hidden md:p-0`}
>
<ConnectedSmall
address={address}
btcWalletBalanceSat={btcWalletBalanceSat}
onDisconnect={onDisconnect}
/>
</div>
</div>
<div className="container mx-auto flex w-full items-center p-6 pb-0 xl:hidden">
<TestingInfo />
</div>
{shouldDisplayTestingMsg() && (
<div className="container mx-auto flex w-full items-center p-6 pb-0 xl:hidden">
<TestingInfo />
</div>
)}
</nav>
);
};
4 changes: 2 additions & 2 deletions src/app/components/Modals/Terms/data/terms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export const Terms = () => {
<p>
If you have any dispute or claim arising out of or relating in any way
to the Interface or these Terms, you must send an email to{" "}
<a href="mailto:contracts@babylonchain.io" className="text-primary">
contracts@babylonchain.io
<a href="mailto:contact@babylonlabs.io" className="text-primary">
contact@babylonlabs.io
</a>{" "}
to resolve the matter via an informal, good faith negotiation process.
If that dispute or claim is not resolved within 60 days of sending such
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const FinalityProviders: React.FC<FinalityProvidersProps> = ({
}

const network = getNetworkConfig().network;
const createFinalityProviderLink = `https://github.com/babylonchain/networks/tree/main/${
const createFinalityProviderLink = `https://github.com/babylonlabs-io/networks/tree/main/${
network == Network.MAINNET ? "bbn-1" : "bbn-test-4"
}/finality-providers`;
return (
Expand Down
7 changes: 7 additions & 0 deletions src/app/components/Staking/Form/States/api-not-available.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/app/components/Staking/Form/States/geo-restricted.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9851b5a

Please sign in to comment.