Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Node.js CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup pnpm
uses: pnpm/action-setup@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '22.x'
cache: 'pnpm'
cache-dependency-path: 'pnpm-lock.yaml'

- name: Install
run: pnpm install --frozen-lockfile

- name: Lint
run: pnpm run lint

- name: Build
run: pnpm run build
51 changes: 0 additions & 51 deletions dist/index.d.mts

This file was deleted.

51 changes: 0 additions & 51 deletions dist/index.d.ts

This file was deleted.

5 changes: 0 additions & 5 deletions dist/index.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.js.map

This file was deleted.

5 changes: 0 additions & 5 deletions dist/index.mjs

This file was deleted.

1 change: 0 additions & 1 deletion dist/index.mjs.map

This file was deleted.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"name": "@bitte-ai/react",
"version": "0.6.6-popup-wallet.1",
"version": "0.0.0",
"description": "React app tools for Bitte Wallet",
"packageManager": "pnpm@10.15.1",
"scripts": {
"watch": "tsc && tsc --watch & jest --watch --coverage",
"lint": "eslint . --fix --ext ts --ext tsx",
"lint": "prettier --check src/.",
"fmt": "prettier --write src/.",
"build": "tsup --config tsup.config.ts --external fsevents",
"prepare": "pnpm run build"
},
Expand Down Expand Up @@ -32,6 +34,7 @@
"@testing-library/user-event": "^14.6.1",
"@types/react": "^19.1.12",
"@types/react-dom": "^19.1.9",
"prettier": "^3.6.2",
"rxjs": "^7.8.2",
"tsup": "^8.5.0",
"typescript": "^5.9.2"
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

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

21 changes: 9 additions & 12 deletions src/BitteWalletContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ export type BitteWalletContext = {

interface ContextProviderType {
children: React.ReactNode;
network?: 'testnet' | 'mainnet';
network?: "testnet" | "mainnet";
onlyMbWallet?: boolean;
contractAddress?: string;
additionalWallets?: Array<WalletModuleFactory>;
onlyBitteWallet?: boolean;
walletUrl?:string
walletUrl?: string;
}

export const BitteWalletContext = createContext<BitteWalletContext | null>(
null
null,
);

export const BitteWalletContextProvider: React.FC<ContextProviderType> = ({
Expand All @@ -57,7 +57,7 @@ export const BitteWalletContextProvider: React.FC<ContextProviderType> = ({
}): JSX.Element => {
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [components, setComponents] = useState<WalletSelectorComponents | null>(
null
null,
);
const [accounts, setAccounts] = useState<AccountState[]>([]);
const [isWaitingForConnection, setIsWaitingForConnection] =
Expand All @@ -82,12 +82,11 @@ export const BitteWalletContextProvider: React.FC<ContextProviderType> = ({
!!onlyBitteWallet ||
!!(additionalWallets && additionalWallets.length > 0);


return await setupBitteWalletSelector(
isOnlyBitteWallet,
selectedNetwork,
{additionalWallets: additionalWallets },
walletUrl
{ additionalWallets: additionalWallets },
walletUrl,
);
};

Expand Down Expand Up @@ -138,7 +137,7 @@ export const BitteWalletContextProvider: React.FC<ContextProviderType> = ({
const subscription = registerWalletAccountsSubscriber(
(accounts: AccountState[]) => {
setAccounts(accounts);
}
},
);

return (): void => {
Expand All @@ -148,8 +147,6 @@ export const BitteWalletContextProvider: React.FC<ContextProviderType> = ({

const { selector, modal } = components || {};



const connect = async (): Promise<void> => {
setIsWaitingForConnection(true);

Expand Down Expand Up @@ -187,7 +184,7 @@ export const BitteWalletContextProvider: React.FC<ContextProviderType> = ({
disconnect,
signMessage,
}),
[selector, modal, accounts]
[selector, modal, accounts],
);

return (
Expand All @@ -201,7 +198,7 @@ export const useBitteWallet = (): BitteWalletContext => {
const context = useContext(BitteWalletContext);
if (!context) {
throw new Error(
"useBitteWallet must be used within a BitteWalletContextProvider"
"useBitteWallet must be used within a BitteWalletContextProvider",
);
}
return context;
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './useNearPrice';
export * from "./useNearPrice";
15 changes: 9 additions & 6 deletions src/hooks/methods/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export const QUERY_OPS_PREFIX = 'mintbase_js_data_';
export const META_SERVICE_HOST = 'https://api.mintbase.xyz';
export const META_SERVICE_HOST_TESTNET = 'https://surface-api-testnet-z3w7d7dnea-ew.a.run.app';
export const BINANCE_API = 'https://api.binance.com/api/v3/ticker/price?symbol=NEARUSDT';
export const COIN_GECKO_API = 'https://api.coingecko.com/api/v3/simple/price?ids=near%2Cusn%2Cjumbo-exchange&include_last_updated_at=true&vs_currencies=usd%2Ceur%2Ccny';
export const MINTBASE_API_KEY_HEADER = 'mb-api-key';
export const QUERY_OPS_PREFIX = "mintbase_js_data_";
export const META_SERVICE_HOST = "https://api.mintbase.xyz";
export const META_SERVICE_HOST_TESTNET =
"https://surface-api-testnet-z3w7d7dnea-ew.a.run.app";
export const BINANCE_API =
"https://api.binance.com/api/v3/ticker/price?symbol=NEARUSDT";
export const COIN_GECKO_API =
"https://api.coingecko.com/api/v3/simple/price?ids=near%2Cusn%2Cjumbo-exchange&include_last_updated_at=true&vs_currencies=usd%2Ceur%2Ccny";
export const MINTBASE_API_KEY_HEADER = "mb-api-key";
1 change: 0 additions & 1 deletion src/hooks/methods/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export interface ParsedDataReturn<T> {
error?: null | string;
data?: T | null;
Expand Down
8 changes: 6 additions & 2 deletions src/hooks/methods/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { ParsedDataReturn } from './types';
import { ParsedDataReturn } from "./types";

export const parseData = <T>(data: T, error?: null | string, errorMsg?: string): ParsedDataReturn<T> => {
export const parseData = <T>(
data: T,
error?: null | string,
errorMsg?: string,
): ParsedDataReturn<T> => {
if (error) {
console.error(errorMsg);
return { error: error };
Expand Down
28 changes: 13 additions & 15 deletions src/hooks/useNearPrice.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect, useState } from 'react';
import { useEffect, useState } from "react";

type UseNearPriceReturn = {
nearPrice: number;
error: string | null;
}
};

export const useNearPrice = (): UseNearPriceReturn => {
const [price, setPrice] = useState<number>(0);
Expand All @@ -28,32 +28,30 @@ export const useNearPrice = (): UseNearPriceReturn => {
};

// Coppied from archived repo: https://github.com/Mintbase/mintbase-js/blob/1661bb879eae3ae4f3e525e69bb2c1aeed1ef77f/packages/data/src/api/nearPrice/nearPrice.ts#L17
const BINANCE_API = 'https://api.binance.com/api/v3/ticker/price?symbol=NEARUSDT';
const BINANCE_API =
"https://api.binance.com/api/v3/ticker/price?symbol=NEARUSDT";

export interface ParsedDataReturn<T> {
error?: null | string;
data?: T | null;
}

export interface NearPriceData {
price?: string;
export interface NearPriceData {
price?: string;
}
export interface CoinGeckoNearPriceData {
near?: {
usd: string;
};
near?: {
usd: string;
};
}


export const nearPrice = async (): Promise<ParsedDataReturn<string>> => {
try {
const req = await fetch(BINANCE_API);
const data: NearPriceData = await req.json();
return {data: data.price || "0"};
return { data: data.price || "0" };
} catch (err: unknown) {
console.error(
`Failed to retrieve near price ${err}`,
);
return {data: "0"};
console.error(`Failed to retrieve near price ${err}`);
return { data: "0" };
}
};
};
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
export * from './BitteWalletContext';
export * from './hooks/useNearPrice';
export type { Wallet, WalletModuleFactory, WalletModule, WalletBehaviourFactory, BrowserWallet, Account } from '@near-wallet-selector/core';
export * from "./BitteWalletContext";
export * from "./hooks/useNearPrice";
export type {
Wallet,
WalletModuleFactory,
WalletModule,
WalletBehaviourFactory,
BrowserWallet,
Account,
} from "@near-wallet-selector/core";
Loading