Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(bos-component): add latest blocks and transactions list #53

Closed
wants to merge 9 commits into from
Closed
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
1,674 changes: 1,673 additions & 1 deletion apps/app/public/common.css

Large diffs are not rendered by default.

Binary file added apps/app/public/images/wavey-fingerprint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions apps/app/src/components/Banners/Banner1.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { useEffect, useState } from 'react';

const Banner1 = () => {
const [isMobile, setIsMobile] = useState(false);

useEffect(() => {
const handleResize = () => {
setIsMobile(window.innerWidth < 768); // Adjust the width threshold as needed
};

handleResize(); // Check initial width

window.addEventListener('resize', handleResize);
return () => window.removeEventListener('resize', handleResize);
}, []);

useEffect(() => {
if (typeof window !== 'undefined') {
// Code to find the walletId
var walletId;
var storage = Object.entries(localStorage);
var found = storage.find(([key]) => /wallet_auth_key*/.test(key));
if (found) {
walletId = JSON.parse(found[1]).accountId;
}

// Create and append the script tag based on device type
const script = document.createElement('script');
if (isMobile) {
script.src = `https://api.pr3sence.xyz/request/content?zone_id=20&walletId=${walletId}&type=js&device=mobile`;
} else {
script.src = `https://api.pr3sence.xyz/request/content?zone_id=21&walletId=${walletId}&type=js&device=desktop`;
}
document.head.appendChild(script);

// Clean up the script tag when the component unmounts
return () => {
document.head.removeChild(script);
};
}
return () => {};
}, [isMobile]);

// Render different content based on device type
if (isMobile) {
return (
<div className="w-full justify-center flex -my-3">
<div style={{ minWidth: 300, minHeight: 100 }}>
<div id="p-d-hp-300x-100x" />
</div>
</div>
);
} else {
return (
<div className="w-full justify-center flex -my-3">
<div style={{ minWidth: 970, minHeight: 90 }}>
<div id="p-d-ll-970x-90x" />
</div>
</div>
);
}
};

export default Banner1;
25 changes: 17 additions & 8 deletions apps/app/src/data/bos-components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,28 @@ import type { NetworkId } from '@/utils/types';
type NetworkComponents = {
nodeExplorer: string;
account: string;
transaction: string;
blocks: string;
latestBlocks: string;
latestTransactions: string;
transactionOverview: string;
};

const ComponentUrl = {
nodeExplorer: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.NodeExplorer`,
account: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.Accounts`,
transaction: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.Transactions.List`,
blocks: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.Blocks.List`,
latestBlocks: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.Blocks.Latest`,
latestTransactions: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.Transactions.Latest`,
transactionOverview: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.Transactions.Overview`,
};

export const componentsByNetworkId: Record<
NetworkId,
NetworkComponents | undefined
> = {
testnet: {
nodeExplorer: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.NearBlocks.NodeExplorer`,
account: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.NearBlocks.Accounts`,
},
testnet: ComponentUrl,

mainnet: {
nodeExplorer: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.NearBlocks.NodeExplorer`,
account: `${process.env.NEXT_PUBLIC_ACCOUNT_ID}/widget/bos-components.components.NearBlocks.Accounts`,
},
mainnet: ComponentUrl,
};
10 changes: 10 additions & 0 deletions apps/app/src/pages/blocks/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { VmComponent } from '@/components/vm/VmComponent';
import { useBosComponents } from '@/hooks/useBosComponents';

const Blocks = () => {
const components = useBosComponents();

return <VmComponent src={components?.blocks} />;
};

export default Blocks;
29 changes: 28 additions & 1 deletion apps/app/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,34 @@ import { useBosComponents } from '@/hooks/useBosComponents';
const HomePage = () => {
const components = useBosComponents();

return <VmComponent src={components?.nodeExplorer} />;
return (
<>
<VmComponent src={components?.transactionOverview} />
<div className="py-8 relative"></div>
<section>
<div className="container mx-auto px-3 z-10">
<div className="grid grid-cols-1 lg:grid-cols-2 gap-4">
<div className="w-full">
<div className="bg-white soft-shadow rounded-lg overflow-hidden mb-6 md:mb-10">
<h2 className="border-b p-3 text-gray-500 text-sm font-semibold">
Latest Blocks
</h2>
<VmComponent src={components?.latestBlocks} />
</div>
</div>
<div className="w-full">
<div className="bg-white soft-shadow rounded-lg overflow-hidden mb-6 md:mb-10">
<h2 className="border-b p-3 text-gray-500 text-sm font-semibold">
Latest Transactions
</h2>
<VmComponent src={components?.latestTransactions} />
</div>
</div>
</div>
</div>
</section>
</>
);
};

export default HomePage;
10 changes: 10 additions & 0 deletions apps/app/src/pages/txns/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { VmComponent } from '@/components/vm/VmComponent';
import { useBosComponents } from '@/hooks/useBosComponents';

const TransactionList = () => {
const components = useBosComponents();

return <VmComponent src={components?.transaction} />;
};

export default TransactionList;
13 changes: 7 additions & 6 deletions apps/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ const env = cleanEnv(process.env, {
DATABASE_KEY: str({ default: '' }),
DATABASE_URL: str(),
LIVECOINWATCH_API_KEY: str(),
NETWORK: str(),
NETWORK: str({
choices: [Network.MAINNET, Network.TESTNET],
}),
RPC_URL: str(),
SENTRY_DSN: str({ default: '' }),
});

const network: Network =
process.env.NETWORK === Network.TESTNET ? Network.TESTNET : Network.MAINNET;
const genesisHeight = network === Network.MAINNET ? 9820210 : 42376888;
const genesisDate = network === Network.MAINNET ? '2020-07-21' : '2021-04-01';
const genesisHeight = env.NETWORK === Network.MAINNET ? 9820210 : 42376888;
const genesisDate =
env.NETWORK === Network.MAINNET ? '2020-07-21' : '2021-04-01';
const sentryDsn = process.env.SENTRY_DSN;

const config: Config = {
Expand All @@ -32,7 +33,7 @@ const config: Config = {
genesisDate,
genesisHeight,
lcwApiKey: env.LIVECOINWATCH_API_KEY,
network,
network: env.NETWORK,
rpcUrl: env.RPC_URL,
sentryDsn,
};
Expand Down
24 changes: 0 additions & 24 deletions apps/bos-components/build.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
import fs from 'fs';
import replaceInFiles from 'replace-in-files';
import postcss from 'postcss';
import postcssPurgecss from '@fullhuman/postcss-purgecss';
import cssnano from 'cssnano';
import tailwindcss from 'tailwindcss';

const transpiledPathPrefix = '.bos/transpiled/src/bos-components';
const css = fs.readFileSync('./src/public/styles.css', 'utf8');
const outputFilePathApp = '../app/public/common.css';

async function build() {
// Process the CSS
let stylesByFile = {};

const postcssPlugins = [
tailwindcss(),
postcssPurgecss({
content: ['src/**/*.tsx'], // Files to search for used classes
}),
cssnano(),
];
const processComponentImports = (filePath, processedFiles = new Set()) => {
if (processedFiles.has(filePath)) {
// Prevent infinite recursion due to cyclic dependencies or repetitive file reads
Expand Down Expand Up @@ -57,14 +41,6 @@ async function build() {
}
};

await postcss(postcssPlugins)
.process(css, { from: 'style.css' })
.then((result) => {
stylesByFile = result.css;
fs.writeFileSync(outputFilePathApp, stylesByFile);
})
.catch(() => {});

await replaceInFiles({
files: [`${transpiledPathPrefix}/**/*.jsx`],
from: /export\s+default\s+function[^(]*\((.*)/gms,
Expand Down
3 changes: 2 additions & 1 deletion apps/bos-components/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
declare const Widget: (params: {
src: string;
src?: string;
props?: object;
}) => React.ReactNode;

Expand All @@ -20,3 +20,4 @@ declare const Dialog;
declare const Select;
declare const ScrollArea;
declare const Buffer;
declare const useMemo;
17 changes: 10 additions & 7 deletions apps/bos-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
"license": "Business Source License 1.1",
"type": "module",
"scripts": {
"build:css": "postcss src/public/styles.css -o ../app/public/common.css",
"start:testnet": "BOS_URL=https://test.near.org/$ACCOUNT/widget/bos-components.components.ExplorerSelector && open $BOS_URL && echo \"Preview at: $BOS_URL\"",
"dev": "yarn start:testnet && bos-loader $ACCOUNT --path .bos/transpiled/src",
"build": "rimraf .bos/transpiled && mkdir -p .bos/transpiled/src && sucrase ./src -d .bos/transpiled/src/bos-components --transforms typescript,jsx --jsx-runtime preserve --disable-es-transforms --out-extension jsx && node ./build.js",
"dev": "yarn build:css & yarn start:testnet && bos-loader $ACCOUNT --path .bos/transpiled/src",
"build": "yarn build:css & rimraf .bos/transpiled && mkdir -p .bos/transpiled/src && sucrase ./src -d .bos/transpiled/src/bos-components --transforms typescript,jsx --jsx-runtime preserve --disable-es-transforms --out-extension jsx && node ./build.js",
"lint": "tsc --noEmit && eslint ./ --fix",
"lint:check": "tsc --noEmit && eslint ./"
},
Expand All @@ -16,20 +17,22 @@
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@csstools/postcss-extract": "^3.0.0",
"@fullhuman/postcss-purgecss": "^5.0.0",
"@types/react": "^18.2.27",
"autoprefixer": "^10.4.16",
"eslint-config-custom-nextjs": "*",
"cssnano": "^6.0.1",
"nb-tsconfig": "*",
"near-social-vm-types": "^1.0.0",
"path": "^0.12.7",
"postcss": "^8.4.31",
"purgecss": "^5.0.0",
"replace-in-files": "^3.0.0",
"rimraf": "^5.0.5",
"sucrase": "^3.34.0",
"nb-tsconfig": "*",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2"
"typescript": "^5.2.2",
"cross-env": "^7.0.3",
"postcss-cli": "^10.1.0",
"postcss-import": "^15.1.0",
"postcss-nested": "^6.0.1",
"postcss-preset-env": "^9.3.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/**
* Component : Accounts
* License : Business Source License 1.1
* Component: Accounts
* Author: Nearblocks Pte Ltd
* License: Business Source License 1.1
* Description: Accounts component enable users to view information related to their accounts.
* @interface Props
* @param {string} [id] - The account identifier passed as a string.
* @param {boolean} [useStyles] - Flag indicating whether to apply default gateway styles; when set to `true`, the component uses default styles, otherwise, it allows for custom styling.
* @param {boolean} [fetchStyles] - Use Nearblock styles.
*/

interface Props {
id?: string;
useStyles?: boolean;
fetchStyles?: boolean;
}

import Skelton from '@/includes/Common/Skelton';
Expand Down Expand Up @@ -66,7 +67,7 @@ export default function (props: Props) {
/**
* Fetches styles asynchronously from a nearblocks gateway.
*/
function fetchStyle() {
function fetchStyles() {
asyncFetch('https://beta.nearblocks.io/common.css').then(
(res: { body: string }) => {
if (res?.body) {
Expand Down Expand Up @@ -337,8 +338,8 @@ export default function (props: Props) {
}, [inventoryData?.fts, props.id, config?.rpcUrl]);

useEffect(() => {
if (props?.useStyles) fetchStyle();
}, [props?.useStyles]);
if (props?.fetchStyles) fetchStyles();
}, [props?.fetchStyles]);

const Theme = styled.div`
${css}
Expand Down
Loading
Loading