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
412 changes: 407 additions & 5 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@
"packages/*"
],
"scripts": {
"build-node": "docker build -t bitcoin-computer-node .",
"build:node": "docker build -t bitcoin-computer-node .",
"clean": "find . -name 'node_modules' -type d -prune -exec rm -rf {} \\;",
"check-obfuscation": "./scripts/check-obfuscation.sh",
"husky-checks": "./scripts/husky-checks.sh",
"prepare": "husky install",
"prepublishOnly": "./scripts/check-obfuscation.sh",
"prepublishOnly": "./scripts/check-obfuscation.sh && npm run test",
"build-all-packages": "turbo run build --concurrency=1",
"types": "npm run types --if-present --workspaces",
"lint": "npm run lint --if-present --workspaces",
"lint-fix": "npm run lint --if-present --workspaces -- --fix",
"lint:fix": "npm run lint --if-present --workspaces -- --fix",
"test": "npm run test --if-present --workspaces"
},
"dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/TBC20/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
},
"scripts": {
"build": "rm -rf build && tsc -p tsconfig.release.json",
"build-turbo": "turbo run build",
"build:turbo": "turbo run build",
"build:watch": "tsc -w -p tsconfig.release.json",
"clean": "rimraf coverage build tmp",
"clean-logs": "rm -f *.log 2> /dev/null",
"lint": "eslint src test --ext .ts,.tsx",
"lint-fix": "eslint src test --ext .ts,.tsx --fix",
"lint:fix": "eslint src test --ext .ts,.tsx --fix",
"prebuild": "npm run lint",
"start": "node build/src/main.js",
"prettier": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,md}\"",
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,md}\"",
"types": "tsc --noEmit",
"test": "mocha --config .mocharc.json",
"test-and-show": "npm run test 2>&1 | tee TBC20-test.log && open TBC20-test.log"
Expand Down
2 changes: 1 addition & 1 deletion packages/TBC721/build/src/nft.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class NftHelper {
async mint(name, artist, url) {
const { tx, effect } = await this.computer.encode({
exp: `new NFT("${name}", "${artist}", "${url}")`,
mod: this.mod
mod: this.mod,
});
await this.computer.broadcast(tx);
return effect.res;
Expand Down
5 changes: 3 additions & 2 deletions packages/TBC721/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"types": "./build/src/index.d.ts",
"scripts": {
"build": "rm -rf build && tsc -p tsconfig.release.json",
"build-turbo": "turbo run build",
"build:turbo": "turbo run build",
"build:watch": "tsc -w -p tsconfig.release.json",
"clean": "rimraf coverage build tmp",
"clean-logs": "rm -f *.log 2> /dev/null",
Expand All @@ -18,7 +18,8 @@
"start": "node build/src/main.js",
"test": "mocha --config .mocharc.json",
"test-and-show": "npm run test 2>&1 | tee tbc721-test.log && open tbc721-test.log",
"types": "tsc --noEmit"
"types": "tsc --noEmit",
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,md}\""
},
"files": [
"build"
Expand Down
2 changes: 1 addition & 1 deletion packages/TBC721/src/nft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class NftHelper implements ITBC721 {
async mint(name: string, artist: string, url: string): Promise<NFT> {
const { tx, effect } = await this.computer.encode({
exp: `new NFT("${name}", "${artist}", "${url}")`,
mod: this.mod
mod: this.mod,
})
await this.computer.broadcast(tx)
return effect.res
Expand Down
2 changes: 1 addition & 1 deletion packages/TBC721/test/nft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const meta = {
_rev: isString,
_root: isString,
_owners: isArray,
_amount: isNumber
_amount: isNumber,
}

describe('NFT', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
"type": "module",
"scripts": {
"dev": "vite",
"start": "vite",
"build": "tsc -b && vite build",
"build-turbo": "turbo run build",
"build:turbo": "turbo run build",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"preview": "vite preview",
"test": "vitest run",
"test:dev": "vitest",
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,scss,md}\"",
"deploy": "node --loader ts-node/esm scripts/deploy.ts"
},
"dependencies": {
Expand Down
8 changes: 4 additions & 4 deletions packages/chat/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { screen, render } from "@testing-library/react"
import App from "./App"
import { screen, render } from '@testing-library/react'
import App from './App'

describe("App", () => {
it("renders the App component", () => {
describe('App', () => {
it('renders the App component', () => {
render(<App />)
const linkElement = screen.getByText(/My Chats/i)
expect(linkElement).toBeInTheDocument()
Expand Down
18 changes: 9 additions & 9 deletions packages/chat/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import "./App.css"
import { useEffect, useState } from "react"
import { BrowserRouter, Route, Routes, Navigate } from "react-router-dom"
import { initFlowbite } from "flowbite"
import './App.css'
import { useEffect, useState } from 'react'
import { BrowserRouter, Route, Routes, Navigate } from 'react-router-dom'
import { initFlowbite } from 'flowbite'
import {
Auth,
Error404,
UtilsContext,
Wallet,
SmartObject,
Transaction,
ComputerContext
} from "@bitcoin-computer/components"
import Mint from "./components/Mint"
import { Chats } from "./components/Chats"
import { Navbar } from "./components/Navbar"
ComputerContext,
} from '@bitcoin-computer/components'
import Mint from './components/Mint'
import { Chats } from './components/Chats'
import { Navbar } from './components/Navbar'

export default function App() {
const [computer] = useState(Auth.getComputer())
Expand Down
4 changes: 2 additions & 2 deletions packages/chat/src/components/Assets.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Auth, Gallery } from "@bitcoin-computer/components"
import { VITE_CHAT_MOD_SPEC } from "../constants/modSpecs"
import { Auth, Gallery } from '@bitcoin-computer/components'
import { VITE_CHAT_MOD_SPEC } from '../constants/modSpecs'

const publicKey = Auth.getComputer().getPublicKey()

Expand Down
84 changes: 42 additions & 42 deletions packages/chat/src/components/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ComputerContext, Modal, sleep, UtilsContext } from "@bitcoin-computer/components"
import { useContext, useEffect, useState } from "react"
import { useNavigate } from "react-router-dom"
import { HiRefresh, HiUserAdd } from "react-icons/hi"
import { ComputerContext, Modal, sleep, UtilsContext } from '@bitcoin-computer/components'
import { useContext, useEffect, useState } from 'react'
import { useNavigate } from 'react-router-dom'
import { HiRefresh, HiUserAdd } from 'react-icons/hi'

import { ChatSc } from "../contracts/chat"
const addUserModal = "add-user-modal"
import { ChatSc } from '../contracts/chat'
const addUserModal = 'add-user-modal'

interface messageI {
text: string
Expand All @@ -13,9 +13,9 @@ interface messageI {
}
const getInitials = (name: string | undefined) => {
if (!name) {
return ""
return ''
}
const names = name.trim().split(" ")
const names = name.trim().split(' ')
if (names.length === 1) return names[0].charAt(0).toUpperCase()
return (names[0].charAt(0) + names[1].charAt(0)).toUpperCase()
}
Expand All @@ -34,28 +34,28 @@ const formatTime = (str: string) => {
const minutes = date.getMinutes()

// Format time
const formattedTime = `${hours < 10 ? "0" + hours : hours}:${minutes < 10 ? "0" + minutes : minutes}`
const formattedTime = `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}`

// Format date as dd mmm yy
const day = date.getDate()
const monthNames = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
]
const month = monthNames[date.getMonth()]
const year = date.getFullYear().toString().slice(-2)

const formattedDate = `${day < 10 ? "0" + day : day} ${month}'${year}`
const formattedDate = `${day < 10 ? '0' + day : day} ${month}'${year}`

return `${formattedDate} ${formattedTime}`
}
Expand Down Expand Up @@ -99,7 +99,7 @@ const SentMessage = ({ message }: { message: messageI }) => {
}

function AddUserToChat(chatObj: ChatSc) {
const [publicKey, setPublicKey] = useState("")
const [publicKey, setPublicKey] = useState('')
const [creating, setCreating] = useState(false)
const { showSnackBar } = UtilsContext.useUtilsComponents()

Expand All @@ -109,8 +109,8 @@ function AddUserToChat(chatObj: ChatSc) {
setCreating(true)
console.log(chatObj)
await chatObj.invite(publicKey)
setPublicKey("")
showSnackBar("User added to the chat", true)
setPublicKey('')
showSnackBar('User added to the chat', true)
Modal.hideModal(addUserModal)
} catch (err) {
if (err instanceof Error) {
Expand Down Expand Up @@ -158,7 +158,7 @@ function AddUserToChat(chatObj: ChatSc) {
const ChatHeader = ({
channelName,
refreshChat,
chatObj
chatObj,
}: {
channelName?: string
refreshChat: () => Promise<void>
Expand All @@ -176,7 +176,7 @@ const ChatHeader = ({
<div className="flex items-center">
<div
className="flex-shrink-0 w-10 h-10 rounded-full flex items-center justify-center text-white text-lg font-semibold"
style={{ backgroundColor: "#0046FF" }}
style={{ backgroundColor: '#0046FF' }}
>
{getInitials(channelName)}
</div>
Expand All @@ -191,16 +191,16 @@ const ChatHeader = ({
<HiRefresh
onClick={refreshChat}
className="w-6 h-6 cursor-pointer hover:opacity-80 dark:hover:opacity-80"
style={{ color: "#999999" }}
style={{ color: '#999999' }}
/>
<HiUserAdd
onClick={() => addUser(chatObj)}
className="w-6 h-6 cursor-pointer hover:opacity-80 dark:hover:opacity-80"
style={{ color: "#999999" }}
style={{ color: '#999999' }}
/>
</div>
<Modal.Component
title={"Add new user to chat"}
title={'Add new user to chat'}
content={AddUserToChat}
id={addUserModal}
contentData={addUserToChat}
Expand All @@ -212,14 +212,14 @@ const ChatHeader = ({
const ChatInput = ({
disabled,
refreshChat,
chatId
chatId,
}: {
chatId: string
disabled: boolean
refreshChat: () => Promise<void>
}) => {
const computer = useContext(ComputerContext)
const [message, setMessage] = useState<string>("")
const [message, setMessage] = useState<string>('')
const [sending, setSending] = useState(false)
const { showSnackBar, showLoader } = UtilsContext.useUtilsComponents()

Expand All @@ -230,14 +230,14 @@ const ChatInput = ({
const messageData: messageI = {
text: message,
publicKey: computer.getPublicKey(),
time: Date.now().toString()
time: Date.now().toString(),
}
const latesRev = await computer.getLatestRev(chatId)
const chatObj = (await computer.sync(latesRev)) as ChatSc
await chatObj.post(JSON.stringify(messageData))
await sleep(2000)
await refreshChat()
setMessage("")
setMessage('')
} catch (error) {
if (error instanceof Error) showSnackBar(error.message, false)
} finally {
Expand All @@ -247,7 +247,7 @@ const ChatInput = ({
}

const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
if (e.key === "Enter" && !e.shiftKey) {
if (e.key === 'Enter' && !e.shiftKey) {
e.preventDefault()
sendMessage()
}
Expand All @@ -259,7 +259,7 @@ const ChatInput = ({
<input
type="text"
className="flex-1 p-2.5 bg-gray-100 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white"
placeholder={disabled ? "You don't have access" : "Type your message..."}
placeholder={disabled ? "You don't have access" : 'Type your message...'}
value={message}
onChange={(e) => setMessage(e.target.value)}
onKeyDown={handleKeyDown}
Expand All @@ -268,7 +268,7 @@ const ChatInput = ({
<button
onClick={sendMessage}
type="button"
className={`p-2.5 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:ring-4 focus:ring-blue-300 dark:bg-blue-500 dark:hover:bg-blue-600 dark:focus:ring-blue-800 ${sending ? "opacity-50 cursor-not-allowed" : ""}`}
className={`p-2.5 text-sm font-medium text-white bg-blue-600 rounded-lg hover:bg-blue-700 focus:ring-4 focus:ring-blue-300 dark:bg-blue-500 dark:hover:bg-blue-600 dark:focus:ring-blue-800 ${sending ? 'opacity-50 cursor-not-allowed' : ''}`}
disabled={sending || disabled}
>
Send
Expand All @@ -282,7 +282,7 @@ export function Chat({ chatId }: { chatId: string }) {
const computer = useContext(ComputerContext)
const { showSnackBar, showLoader } = UtilsContext.useUtilsComponents()
const navigate = useNavigate()
const [id] = useState(chatId || "")
const [id] = useState(chatId || '')
const [chatObj, setChatObj] = useState<ChatSc | null>(null)
const [messages, setMessages] = useState<messageI[]>([])

Expand All @@ -300,7 +300,7 @@ export function Chat({ chatId }: { chatId: string }) {
showLoader(false)
} catch {
showLoader(false)
showSnackBar("Not a valid Chat", false)
showSnackBar('Not a valid Chat', false)
}
}

Expand All @@ -313,10 +313,10 @@ export function Chat({ chatId }: { chatId: string }) {

return (
<>
<div className="grid grid-cols-1 gap-4 max-w" style={{ maxHeight: "calc(100vh - 10vh)" }}>
<div className="grid grid-cols-1 gap-4 max-w" style={{ maxHeight: 'calc(100vh - 10vh)' }}>
<div
className="flex flex-col bg-gray-50 dark:bg-gray-800 max-w"
style={{ minHeight: "calc(100vh - 10vh)", maxHeight: "calc(100vh - 10vh)" }}
style={{ minHeight: 'calc(100vh - 10vh)', maxHeight: 'calc(100vh - 10vh)' }}
>
{chatObj && (
<>
Expand All @@ -332,7 +332,7 @@ export function Chat({ chatId }: { chatId: string }) {
<SentMessage message={data} key={`${chatObj?._id}_${index.toString()}`} />
) : (
<ReceivedMessage message={data} key={`${chatObj?._id}_${index.toString()}`} />
)
),
)}
</div>

Expand Down
Loading