Skip to content

Commit 2f65b34

Browse files
committed
nebula interface
1 parent 0b4045b commit 2f65b34

File tree

15 files changed

+715
-248
lines changed

15 files changed

+715
-248
lines changed

apps/dashboard/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
"@radix-ui/react-separator": "^1.1.1",
4646
"@radix-ui/react-slot": "^1.1.1",
4747
"@radix-ui/react-switch": "^1.1.2",
48-
"@radix-ui/react-tabs": "^1.1.2",
4948
"@radix-ui/react-tooltip": "1.1.7",
5049
"@sentry/nextjs": "8.51.0",
5150
"@shazow/whatsabi": "^0.19.0",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use server";
2+
import assert from "node:assert";
3+
import { DASHBOARD_THIRDWEB_SECRET_KEY } from "@/constants/env";
4+
5+
export async function createNebulaSesssion(args: {
6+
chainId: number;
7+
address: string;
8+
}): Promise<string> {
9+
try {
10+
const { NEXT_PUBLIC_NEBULA_URL } = process.env;
11+
assert(NEXT_PUBLIC_NEBULA_URL, "NEXT_PUBLIC_NEBULA_URL is not set");
12+
const { chainId, address } = args;
13+
14+
const response = await fetch(`${NEXT_PUBLIC_NEBULA_URL}/session`, {
15+
method: "POST",
16+
headers: {
17+
"Content-Type": "application/json",
18+
Authorization: `Bearer ${DASHBOARD_THIRDWEB_SECRET_KEY}`,
19+
},
20+
body: JSON.stringify({
21+
title: `Wallet Overview - ${chainId}:${address}`,
22+
context_filter: {
23+
chainIds: [chainId],
24+
walletAddresses: [address],
25+
},
26+
}),
27+
});
28+
if (!response.ok) {
29+
throw new Error(
30+
`Unexpected status ${response.status}: ${await response.text()}`,
31+
);
32+
}
33+
34+
const data = await response.json();
35+
return data.result.id;
36+
} catch (error) {
37+
console.error("Error creating Nebula session:", error);
38+
throw error;
39+
}
40+
}

apps/dashboard/src/app/(dashboard)/hackweek/[chain_id]/[address]/actions/fetchERC20Tokens.ts

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,58 @@
33
import assert from "node:assert";
44
import type { TokenDetails } from "../hooks/useGetERC20Tokens";
55

6+
// "native_tokens": [
7+
// {
8+
// "token_id": "ethereum.native",
9+
// "name": "Ether",
10+
// "symbol": "ETH",
11+
// "decimals": 18,
12+
// "chain": "ethereum",
13+
// "total_quantity": 1527391387004726000,
14+
// "total_quantity_string": "1527391387004725927",
15+
// "total_value_usd_cents": 477180,
16+
// "queried_wallet_balances": [
17+
// {
18+
// "address": "0xa5B8492D8223D255dB279C7c3ebdA34Be5eC9D85",
19+
// "quantity": 1527391387004726000,
20+
// "quantity_string": "1527391387004725927",
21+
// "value_usd_cents": 477180
22+
// }
23+
// ]
24+
// }
25+
// ]
26+
27+
interface QueriedWalletBalance {
28+
address: string;
29+
quantity_string: string;
30+
value_usd_cents: number;
31+
first_transferred_date: string;
32+
last_transferred_date: string;
33+
}
34+
35+
interface FungibleToken {
36+
fungible_id: string;
37+
name: string;
38+
symbol: string;
39+
decimals: number;
40+
total_quantity_string: string;
41+
total_value_usd_cents: number;
42+
queried_wallet_balances: QueriedWalletBalance[];
43+
}
44+
45+
interface NativeToken {
46+
token_id: string;
47+
name: string;
48+
symbol: string;
49+
decimals: number;
50+
total_quantity_string: string;
51+
total_value_usd_cents: number;
52+
queried_wallet_balances: QueriedWalletBalance[];
53+
}
54+
655
interface SimpleHashResponse {
7-
fungibles: {
8-
name: string;
9-
symbol: string;
10-
decimals: number;
11-
total_quantity_string: string;
12-
total_value_usd_string: string;
13-
}[];
56+
fungibles: FungibleToken[];
57+
native_tokens: NativeToken[];
1458
next_cursor: string | null;
1559
}
1660

@@ -24,7 +68,7 @@ export async function fetchERC20Tokens(args: {
2468
const { chainId, address } = args;
2569

2670
const response = await fetch(
27-
`https://api.simplehash.com/api/v0/fungibles/balances?chains=eip155:${chainId}&wallet_addresses=${address}&include_fungible_details=1&include_prices=1&count=0&limit=50&order_by=last_transferred_date__desc&include_native_tokens=0`,
71+
`https://api.simplehash.com/api/v0/fungibles/balances?chains=eip155:${chainId}&wallet_addresses=${address}&include_fungible_details=0&include_prices=1&count=0&limit=50&order_by=last_transferred_date__desc&include_native_tokens=1`,
2872
{
2973
headers: { "X-API-KEY": SIMPLEHASH_API_KEY },
3074
},
@@ -36,13 +80,31 @@ export async function fetchERC20Tokens(args: {
3680
}
3781

3882
const data: SimpleHashResponse = await response.json();
39-
return data.fungibles.map((token) => ({
83+
const nativeTokens = data.native_tokens.map((token) => ({
84+
name: token.name,
85+
symbol: token.symbol,
86+
contractAddress: "Native",
87+
decimals: token.decimals,
88+
balance: BigInt(token.total_quantity_string ?? 0n),
89+
totalValueUsdCents: token.total_value_usd_cents,
90+
firstTransferredDate:
91+
token.queried_wallet_balances[0]?.first_transferred_date,
92+
lastTransferredDate:
93+
token.queried_wallet_balances[0]?.last_transferred_date,
94+
}));
95+
const fungibleTokens = data.fungibles.map((token) => ({
4096
name: token.name,
4197
symbol: token.symbol,
98+
contractAddress: token.fungible_id.split(".")[1] ?? "--",
4299
decimals: token.decimals,
43-
balance: token.total_quantity_string,
44-
totalValueUsdString: token.total_value_usd_string,
100+
balance: BigInt(token.total_quantity_string ?? 0n),
101+
totalValueUsdCents: token.total_value_usd_cents,
102+
firstTransferredDate:
103+
token.queried_wallet_balances[0]?.first_transferred_date,
104+
lastTransferredDate:
105+
token.queried_wallet_balances[0]?.last_transferred_date,
45106
}));
107+
return [...nativeTokens, ...fungibleTokens];
46108
} catch (error) {
47109
console.error("Error fetching tokens:", error);
48110
return [];

0 commit comments

Comments
 (0)