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
14 changes: 3 additions & 11 deletions src/api/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EarningTransaction, InviteInfo, Plugin, PluginApiKey, PluginPricing, TeamMember, TeamMemberRole } from "@/utils/types";
import { EarningsSummary, EarningTransaction, InviteInfo, Plugin, PluginApiKey, PluginPricing, TeamMember, TeamMemberRole } from "@/utils/types";

import { apiClient } from "./client";

Expand Down Expand Up @@ -172,16 +172,8 @@ export const getEarnings = async (filters?: EarningsFilters): Promise<EarningsRe
};
};

export const getEarningsSummary = async (): Promise<{
totalEarnings: number;
totalTransactions: number;
earningsByPlugin: Record<string, number>;
}> => {
const response = await apiClient.get<{
totalEarnings: number;
totalTransactions: number;
earningsByPlugin: Record<string, number>;
}>("/earnings/summary");
export const getEarningsSummary = async (): Promise<EarningsSummary> => {
const response = await apiClient.get<EarningsSummary>("/earnings/summary");
return response.data;
};

Expand Down
60 changes: 34 additions & 26 deletions src/data/mockData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { EarningTransaction, Plugin, PluginApiKey, PluginPricing } from "@/utils/types";

// Default USDC fee asset for mock data
const mockFeeAsset = {
symbol: "USDC",
addr: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
decimals: 6,
network: "ethereum",
};

// Mock Plugins based on seed data
export const mockPlugins: Plugin[] = [
{
Expand Down Expand Up @@ -64,42 +72,42 @@ export const mockPlugins: Plugin[] = [
},
];

// Mock Pricing based on seed data
// Mock Pricing based on seed data (amounts in minimal units)
export const mockPricings: PluginPricing[] = [
{
id: "00000000-0000-0000-0000-000000000002",
pluginId: "vultisig-dca-0000",
asset: "usdc",
type: "per-tx",
frequency: null,
amount: 10000, // 1 cent in micro units
amount: "10000", // 0.01 USDC
fee_asset: mockFeeAsset,
metric: "fixed",
},
{
id: "00000000-0000-0000-0000-000000000003",
pluginId: "vultisig-payroll-0000",
asset: "usdc",
type: "once",
frequency: null,
amount: 50000, // 5 cents
amount: "50000", // 0.05 USDC
fee_asset: mockFeeAsset,
metric: "fixed",
},
{
id: "00000000-0000-0000-0000-000000000004",
pluginId: "vultisig-payroll-0000",
asset: "usdc",
type: "recurring",
frequency: "monthly",
amount: 30000, // 3 cents
amount: "30000", // 0.03 USDC
fee_asset: mockFeeAsset,
metric: "fixed",
},
{
id: "00000000-0000-0000-0000-000000000005",
pluginId: "vultisig-copytrader-0000",
asset: "usdc",
type: "per-tx",
frequency: null,
amount: 10000, // 1 cent
amount: "10000", // 0.01 USDC
fee_asset: mockFeeAsset,
metric: "fixed",
},
];
Expand Down Expand Up @@ -132,14 +140,14 @@ export const mockApiKeys: PluginApiKey[] = [
},
];

// Mock Earning Transactions
// Mock Earning Transactions (amounts in minimal units, e.g., 10000 = 0.01 USDC)
export const mockEarnings: EarningTransaction[] = [
{
id: "tx-001",
pluginId: "vultisig-dca-0000",
pluginName: "Vultisig DCA Plugin",
amount: 10000,
asset: "usdc",
amount: "10000",
fee_asset: mockFeeAsset,
type: "per-tx",
createdAt: "2024-04-10T14:32:00Z",
fromAddress: "0x1234...5678",
Expand All @@ -150,8 +158,8 @@ export const mockEarnings: EarningTransaction[] = [
id: "tx-002",
pluginId: "vultisig-dca-0000",
pluginName: "Vultisig DCA Plugin",
amount: 10000,
asset: "usdc",
amount: "10000",
fee_asset: mockFeeAsset,
type: "per-tx",
createdAt: "2024-04-10T12:15:00Z",
fromAddress: "0x8765...4321",
Expand All @@ -162,8 +170,8 @@ export const mockEarnings: EarningTransaction[] = [
id: "tx-003",
pluginId: "vultisig-payroll-0000",
pluginName: "Vultisig Payroll Plugin",
amount: 50000,
asset: "usdc",
amount: "50000",
fee_asset: mockFeeAsset,
type: "once",
createdAt: "2024-04-09T10:00:00Z",
fromAddress: "0xabcd...efgh",
Expand All @@ -174,8 +182,8 @@ export const mockEarnings: EarningTransaction[] = [
id: "tx-004",
pluginId: "vultisig-payroll-0000",
pluginName: "Vultisig Payroll Plugin",
amount: 30000,
asset: "usdc",
amount: "30000",
fee_asset: mockFeeAsset,
type: "recurring",
createdAt: "2024-04-01T00:00:00Z",
fromAddress: "0xijkl...mnop",
Expand All @@ -186,8 +194,8 @@ export const mockEarnings: EarningTransaction[] = [
id: "tx-005",
pluginId: "vultisig-copytrader-0000",
pluginName: "Vultisig Copytrader Plugin",
amount: 10000,
asset: "usdc",
amount: "10000",
fee_asset: mockFeeAsset,
type: "per-tx",
createdAt: "2024-04-08T16:45:00Z",
fromAddress: "0xqrst...uvwx",
Expand All @@ -198,8 +206,8 @@ export const mockEarnings: EarningTransaction[] = [
id: "tx-006",
pluginId: "vultisig-dca-0000",
pluginName: "Vultisig DCA Plugin",
amount: 10000,
asset: "usdc",
amount: "10000",
fee_asset: mockFeeAsset,
type: "per-tx",
createdAt: "2024-04-07T09:20:00Z",
fromAddress: "0xyzab...cdef",
Expand All @@ -210,8 +218,8 @@ export const mockEarnings: EarningTransaction[] = [
id: "tx-007",
pluginId: "vultisig-copytrader-0000",
pluginName: "Vultisig Copytrader Plugin",
amount: 10000,
asset: "usdc",
amount: "10000",
fee_asset: mockFeeAsset,
type: "per-tx",
createdAt: "2024-04-06T11:30:00Z",
fromAddress: "0xghij...klmn",
Expand All @@ -222,8 +230,8 @@ export const mockEarnings: EarningTransaction[] = [
id: "tx-008",
pluginId: "vultisig-payroll-0000",
pluginName: "Vultisig Payroll Plugin",
amount: 30000,
asset: "usdc",
amount: "30000",
fee_asset: mockFeeAsset,
type: "recurring",
createdAt: "2024-03-01T00:00:00Z",
fromAddress: "0xopqr...stuv",
Expand Down
14 changes: 5 additions & 9 deletions src/pages/Earnings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useCore } from "@/hooks/useCore";
import { Spin } from "@/toolkits/Spin";
import { HStack, Stack, VStack } from "@/toolkits/Stack";
import { formatCurrency, formatDate, truncateAddress } from "@/utils/functions";
import { EarningTransaction, Plugin } from "@/utils/types";
import { EarningsSummary, EarningTransaction, Plugin } from "@/utils/types";

const { RangePicker } = DatePicker;

Expand All @@ -20,11 +20,7 @@ export const EarningsPage = () => {
const [loading, setLoading] = useState(true);
const [earnings, setEarnings] = useState<EarningTransaction[]>([]);
const [plugins, setPlugins] = useState<Plugin[]>([]);
const [summary, setSummary] = useState<{
totalEarnings: number;
totalTransactions: number;
earningsByPlugin: Record<string, number>;
} | null>(null);
const [summary, setSummary] = useState<EarningsSummary | null>(null);

// Pagination
const [page, setPage] = useState(1);
Expand Down Expand Up @@ -86,9 +82,9 @@ export const EarningsPage = () => {
title: "Amount",
dataIndex: "amount",
key: "amount",
render: (amount: number, record) => (
render: (amount: string, record) => (
<Stack $style={{ fontWeight: "600", color: colors.success.toHex() }}>
+{formatCurrency(amount, 4)} {record.asset.toUpperCase()}
+{formatCurrency(amount, record.fee_asset.decimals)} {record.fee_asset.symbol}
</Stack>
),
},
Expand Down Expand Up @@ -210,7 +206,7 @@ export const EarningsPage = () => {
Total Earnings
</Stack>
<Stack $style={{ fontSize: "28px", fontWeight: "600", color: colors.success.toHex() }}>
{formatCurrency(summary.totalEarnings, 4)}
{formatCurrency(summary.totalEarnings.amount, summary.totalEarnings.fee_asset.decimals)}
</Stack>
</VStack>

Expand Down
4 changes: 2 additions & 2 deletions src/pages/PluginEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,11 @@ export const PluginEditPage = () => {
{pricing.frequency && ` (${pricing.frequency})`}
</Stack>
<Stack $style={{ fontSize: "12px", color: colors.textTertiary.toHex() }}>
{pricing.asset.toUpperCase()} - {pricing.metric}
{pricing.fee_asset.symbol} - {pricing.metric}
</Stack>
</VStack>
<Stack $style={{ fontSize: "18px", fontWeight: "600" }}>
{formatCurrency(pricing.amount, 4)}
{formatCurrency(pricing.amount, pricing.fee_asset.decimals)}
</Stack>
</HStack>
))}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Plugins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const PluginsPage = () => {
{record.pricings.length > 0 ? (
record.pricings.map((pricing) => (
<Stack key={pricing.id} $style={{ fontSize: "12px" }}>
{formatCurrency(pricing.amount, 4)} {pricing.asset.toUpperCase()} / {pricing.type}
{formatCurrency(pricing.amount, pricing.fee_asset.decimals)} {pricing.fee_asset.symbol} / {pricing.type}
{pricing.frequency && ` (${pricing.frequency})`}
</Stack>
))
Expand Down
8 changes: 6 additions & 2 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,12 @@ export const formatDate = (dateString: string): string => {
});
};

export const formatCurrency = (amount: number, decimals = 6): string => {
const value = amount / Math.pow(10, decimals);
export const formatCurrency = (amount: string | number, decimals = 6): string => {
const parsed = typeof amount === "string" ? parseFloat(amount) : amount;
if (isNaN(parsed)) {
return "$0.00";
}
const value = parsed / Math.pow(10, decimals);
return `$${value.toFixed(2)}`;
};

Expand Down
26 changes: 22 additions & 4 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export type Plugin = {
export type PluginPricing = {
id: string;
pluginId: string;
asset: string;
type: "per-tx" | "once" | "recurring";
frequency: string | null;
amount: number;
amount: string;
fee_asset: FeeAsset;
metric: string;
};

Expand All @@ -45,19 +45,37 @@ export type PluginApiKey = {
status: number;
};

export type FeeAsset = {
symbol: string;
addr: string;
decimals: number;
network: string;
};

export type EarningTransaction = {
id: string;
pluginId: string;
pluginName: string;
amount: number;
asset: string;
amount: string;
fee_asset: FeeAsset;
type: "per-tx" | "once" | "recurring";
createdAt: string;
fromAddress: string;
txHash: string;
status: "pending" | "completed" | "failed";
};

export type PluginEarning = {
amount: string;
fee_asset: FeeAsset;
};

export type EarningsSummary = {
totalEarnings: PluginEarning;
totalTransactions: number;
earningsByPlugin: Record<string, PluginEarning>;
};

export type Tag = {
id: string;
name: string;
Expand Down