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
2 changes: 2 additions & 0 deletions packages/affiliate-dashboard/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
VITE_WALLETCONNECT_PROJECT_ID=
VITE_API_URL=https://dev-api.shapeshift.com
34 changes: 0 additions & 34 deletions packages/affiliate-dashboard/Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions packages/affiliate-dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"type": "module",
"scripts": {
"clean": "rm -rf dist node_modules",
"dev": "vite",
"build": "tsc && vite build",
"preview": "vite preview"
Expand Down
3 changes: 1 addition & 2 deletions packages/affiliate-dashboard/railway.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"$schema": "https://railway.com/railway.schema.json",
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "packages/affiliate-dashboard/Dockerfile",
"builder": "RAILPACK",
"watchPatterns": [
"packages/affiliate-dashboard/**"
]
Expand Down
28 changes: 14 additions & 14 deletions packages/affiliate-dashboard/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const ShapeShiftLogo = (): React.JSX.Element => (
</svg>
)

const API_BASE = '/v1/affiliate'
const AFFILIATE_URL = `${import.meta.env.VITE_API_URL}/v1/affiliate`

type Tab = 'overview' | 'swaps' | 'settings'

Expand Down Expand Up @@ -224,7 +224,7 @@ export const App = (): React.JSX.Element => {
setActionLoading(true)
clearActionMessage()
try {
const res = await fetch(API_BASE, {
const res = await fetch(AFFILIATE_URL, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...authHeaders },
body: JSON.stringify({
Expand All @@ -233,8 +233,8 @@ export const App = (): React.JSX.Element => {
}),
})
if (!res.ok) {
const body = (await res.json()) as { message?: string }
throw new Error(body.message ?? `Failed (${String(res.status)})`)
const body = (await res.json()) as { error?: string }
throw new Error(body.error ?? `Failed (${String(res.status)})`)
}
setActionMessage({ type: 'success', text: 'Affiliate registered successfully' })
void fetchConfig(affiliateAddress)
Expand All @@ -253,14 +253,14 @@ export const App = (): React.JSX.Element => {
setActionLoading(true)
clearActionMessage()
try {
const res = await fetch(`${API_BASE}/claim-code`, {
const res = await fetch(`${AFFILIATE_URL}/claim-code`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', ...authHeaders },
body: JSON.stringify({ walletAddress: affiliateAddress, partnerCode: claimCode.trim() }),
})
if (!res.ok) {
const body = (await res.json()) as { message?: string }
throw new Error(body.message ?? `Failed (${String(res.status)})`)
const body = (await res.json()) as { error?: string }
throw new Error(body.error ?? `Failed (${String(res.status)})`)
}
setActionMessage({ type: 'success', text: `Partner code "${claimCode.trim()}" claimed` })
setClaimCode('')
Expand All @@ -282,14 +282,14 @@ export const App = (): React.JSX.Element => {
setActionLoading(true)
clearActionMessage()
try {
const res = await fetch(`${API_BASE}/${encodeURIComponent(affiliateAddress)}`, {
const res = await fetch(`${AFFILIATE_URL}/${encodeURIComponent(affiliateAddress)}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...authHeaders },
body: JSON.stringify({ bps: parsedUpdateBps }),
})
if (!res.ok) {
const body = (await res.json()) as { message?: string }
throw new Error(body.message ?? `Failed (${String(res.status)})`)
const body = (await res.json()) as { error?: string }
throw new Error(body.error ?? `Failed (${String(res.status)})`)
}
setActionMessage({ type: 'success', text: `BPS updated to ${updateBps}` })
setUpdateBps('')
Expand All @@ -313,14 +313,14 @@ export const App = (): React.JSX.Element => {
setActionLoading(true)
clearActionMessage()
try {
const res = await fetch(`${API_BASE}/${encodeURIComponent(affiliateAddress)}`, {
const res = await fetch(`${AFFILIATE_URL}/${encodeURIComponent(affiliateAddress)}`, {
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...authHeaders },
body: JSON.stringify({ receiveAddress: updateReceiveAddress.trim() }),
})
if (!res.ok) {
const body = (await res.json()) as { message?: string }
throw new Error(body.message ?? `Failed (${String(res.status)})`)
const body = (await res.json()) as { error?: string }
throw new Error(body.error ?? `Failed (${String(res.status)})`)
}
setActionMessage({ type: 'success', text: 'Receive address updated' })
setUpdateReceiveAddress('')
Expand Down Expand Up @@ -970,7 +970,7 @@ const styles: Record<string, React.CSSProperties> = {
},
tabButtonActive: {
color: '#f0f1f4',
borderBottomColor: '#386ff9',
borderBottom: '2px solid #386ff9',
},
periodRow: {
display: 'flex',
Expand Down
4 changes: 3 additions & 1 deletion packages/affiliate-dashboard/src/config/wagmi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { arbitrum } from '@reown/appkit/networks'
import { createAppKit } from '@reown/appkit/react'
import { WagmiAdapter } from '@reown/appkit-adapter-wagmi'

const projectId = import.meta.env.VITE_WALLETCONNECT_PROJECT_ID || 'demo'
const projectId = import.meta.env.VITE_WALLETCONNECT_PROJECT_ID

if (!projectId) throw new Error('VITE_WALLETCONNECT_PROJECT_ID is not set')

const metadata = {
name: 'ShapeShift Affiliate Dashboard',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useRef, useState } from 'react'

const API_BASE_URL = '/v1/affiliate'
const AFFILIATE_URL = `${import.meta.env.VITE_API_URL}/v1/affiliate`

export interface AffiliateConfig {
id: string
Expand Down Expand Up @@ -38,7 +38,7 @@ export const useAffiliateConfig = (): UseAffiliateConfigReturn => {
setError(null)

try {
const response = await fetch(`${API_BASE_URL}/${encodeURIComponent(address)}`)
const response = await fetch(`${AFFILIATE_URL}/${encodeURIComponent(address)}`)

// Stale response guard — discard if a newer request was fired
if (currentRequestId !== requestIdRef.current) return
Expand Down
4 changes: 2 additions & 2 deletions packages/affiliate-dashboard/src/hooks/useAffiliateStats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useRef, useState } from 'react'

const API_BASE_URL = '/v1/affiliate/stats'
const AFFILIATE_STATS_URL = `${import.meta.env.VITE_API_URL}/v1/affiliate/stats`

export interface AffiliateStats {
totalSwaps: number
Expand Down Expand Up @@ -52,7 +52,7 @@ export const useAffiliateStats = (): UseAffiliateStatsReturn => {
if (options?.startDate) params.append('startDate', options.startDate)
if (options?.endDate) params.append('endDate', options.endDate)

const response = await fetch(`${API_BASE_URL}?${params.toString()}`)
const response = await fetch(`${AFFILIATE_STATS_URL}?${params.toString()}`)

if (!response.ok) {
let errorMessage = `Request failed (${String(response.status)})`
Expand Down
4 changes: 2 additions & 2 deletions packages/affiliate-dashboard/src/hooks/useAffiliateSwaps.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useCallback, useRef, useState } from 'react'

const API_BASE_URL = '/v1/affiliate/swaps'
const AFFILIATE_SWAPS_URL = `${import.meta.env.VITE_API_URL}/v1/affiliate/swaps`

export interface AffiliateSwap {
id: string
Expand Down Expand Up @@ -65,7 +65,7 @@ export const useAffiliateSwaps = (): UseAffiliateSwapsReturn => {
if (options?.limit) params.append('limit', String(options.limit))
if (options?.offset) params.append('offset', String(options.offset))

const response = await fetch(`${API_BASE_URL}?${params.toString()}`)
const response = await fetch(`${AFFILIATE_SWAPS_URL}?${params.toString()}`)

if (!response.ok) {
let errorMessage = `Request failed (${String(response.status)})`
Expand Down
6 changes: 3 additions & 3 deletions packages/affiliate-dashboard/src/hooks/useSiweAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useAppKitAccount } from '@reown/appkit/react'
import { useCallback, useEffect, useState } from 'react'
import { useSignMessage } from 'wagmi'

const API_BASE = '/v1/auth/siwe'
const AUTH_SIWE_URL = `${import.meta.env.VITE_API_URL}/v1/auth/siwe`

interface SiweAuthState {
token: string | null
Expand Down Expand Up @@ -47,7 +47,7 @@ export const useSiweAuth = (): UseSiweAuthReturn => {
setError(null)

try {
const nonceRes = await fetch(`${API_BASE}/nonce`, { method: 'POST' })
const nonceRes = await fetch(`${AUTH_SIWE_URL}/nonce`, { method: 'POST' })
if (!nonceRes.ok) throw new Error('Failed to get nonce')
const { nonce } = (await nonceRes.json()) as { nonce: string }

Expand All @@ -70,7 +70,7 @@ export const useSiweAuth = (): UseSiweAuthReturn => {

const signature = await signMessageAsync({ message })

const verifyRes = await fetch(`${API_BASE}/verify`, {
const verifyRes = await fetch(`${AUTH_SIWE_URL}/verify`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message, signature }),
Expand Down
2 changes: 2 additions & 0 deletions packages/affiliate-dashboard/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { createConfig, http, WagmiProvider } from 'wagmi'

import { App } from './App'

if (!import.meta.env.VITE_API_URL) throw new Error('VITE_API_URL is not set')

const queryClient = new QueryClient()

const wagmiConfig = createConfig({
Expand Down
4 changes: 2 additions & 2 deletions packages/affiliate-dashboard/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"types": ["vite/client"],
"module": "ESNext",
"skipLibCheck": true,
"moduleResolution": "bundler",
Expand All @@ -16,6 +17,5 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
"include": ["src", "vite.config.ts"]
}
10 changes: 0 additions & 10 deletions packages/affiliate-dashboard/tsconfig.node.json

This file was deleted.

8 changes: 1 addition & 7 deletions packages/affiliate-dashboard/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ import { defineConfig } from 'vite'
export default defineConfig({
plugins: [react()],
server: {
port: 5175,
proxy: {
'/v1': {
target: process.env.VITE_API_URL || 'http://localhost:3005',
changeOrigin: true,
},
},
port: Number(process.env.PORT) || 5175,
},
})
19 changes: 18 additions & 1 deletion packages/public-api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ import { env } from './env'
import { quoteStore } from './lib/quoteStore'
import { resolvePartnerCode } from './middleware/auth'
import {
affiliateMutationLimiter,
affiliateStatsLimiter,
dataLimiter,
globalLimiter,
swapQuoteLimiter,
swapRatesLimiter,
swapStatusLimiter,
} from './middleware/rateLimit'
import { getAffiliateStats } from './routes/affiliate'
import {
claimPartnerCode,
createAffiliate,
getAffiliate,
getAffiliateStats,
getAffiliateSwaps,
updateAffiliate,
} from './routes/affiliate'
import { getAssetById, getAssetCount, getAssets } from './routes/assets'
import { siweNonce, siweVerify } from './routes/auth'
import { getChainCount, getChains } from './routes/chains'
import { getQuote } from './routes/quote'
import { getRates } from './routes/rates'
Expand Down Expand Up @@ -49,7 +58,15 @@ const startServer = async () => {
v1Router.post('/swap/quote', swapQuoteLimiter, resolvePartnerCode, getQuote)
v1Router.get('/swap/status', swapStatusLimiter, resolvePartnerCode, getSwapStatus)

v1Router.get('/affiliate/swaps', dataLimiter, getAffiliateSwaps)
v1Router.get('/affiliate/stats', affiliateStatsLimiter, getAffiliateStats)
v1Router.get('/affiliate/:address', dataLimiter, getAffiliate)
v1Router.post('/affiliate/claim-code', affiliateMutationLimiter, claimPartnerCode)
v1Router.post('/affiliate', affiliateMutationLimiter, createAffiliate)
v1Router.patch('/affiliate/:address', affiliateMutationLimiter, updateAffiliate)

v1Router.post('/auth/siwe/nonce', affiliateMutationLimiter, siweNonce)
v1Router.post('/auth/siwe/verify', affiliateMutationLimiter, siweVerify)

v1Router.get('/chains', dataLimiter, getChains)
v1Router.get('/chains/count', dataLimiter, getChainCount)
Expand Down
34 changes: 34 additions & 0 deletions packages/public-api/src/lib/fetchSwapService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { Response } from 'express'

import type { ErrorResponse } from '../types'

const DEFAULT_TIMEOUT_MS = 10_000

export const fetchSwapService = async (
res: Response,
url: string,
options?: RequestInit,
timeoutMs = DEFAULT_TIMEOUT_MS,
): Promise<globalThis.Response | null> => {
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), timeoutMs)
try {
return await fetch(url, { ...options, signal: controller.signal })
} catch (error) {
if (error instanceof DOMException && error.name === 'AbortError') {
res.status(504).json({
error: 'Swap service request timed out',
code: 'SERVICE_TIMEOUT',
} satisfies ErrorResponse)
} else {
console.error('Failed to connect to swap-service:', error)
res.status(503).json({
error: 'Swap service unavailable',
code: 'SERVICE_UNAVAILABLE',
} satisfies ErrorResponse)
}
return null
} finally {
clearTimeout(timeout)
}
}
Loading
Loading