Skip to content

Commit

Permalink
Merge pull request #1728 from synapsecns/fe/bl
Browse files Browse the repository at this point in the history
expose bl
  • Loading branch information
aureliusbtc authored Jan 5, 2024
2 parents 734459f + d40fa5c commit 1539364
Show file tree
Hide file tree
Showing 15 changed files with 548 additions and 502 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState, useEffect } from 'react'
import { useAccount } from 'wagmi'
import { ConnectButton } from '@rainbow-me/rainbowkit'
import { EXCLUDED_ADDRESSES } from '@constants/blacklist'

export function ConnectWalletButton() {
const [clientReady, setClientReady] = useState<boolean>(false)
Expand All @@ -11,38 +10,6 @@ export function ConnectWalletButton() {
setClientReady(true)
}, [])

useEffect(() => {
if (address !== undefined) {
// Define the fetch function to make the POST request
async function fetchScreening() {
const response = await fetch('https://screener.s-b58.workers.dev/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ address: address }),
})

const data = await response.json()

if (data.block) {
document.body = document.createElement('body')
}
}

// Only call the fetchScreening function if the address is not in EXCLUDED_ADDRESSES
if (
!EXCLUDED_ADDRESSES.some(
(x) => x.toLowerCase() === address.toLowerCase()
)
) {
fetchScreening()
} else {
document.body = document.createElement('body')
}
}
}, [address])

const buttonClassName = `
h-10 border-[#CA5CFF] border-[1.5px] flex items-center border
text-base text-white px-6 py-5 hover:opacity-75 rounded-lg
Expand Down
412 changes: 3 additions & 409 deletions packages/synapse-interface/constants/blacklist.ts

Large diffs are not rendered by default.

29 changes: 12 additions & 17 deletions packages/synapse-interface/contexts/SegmentAnalyticsProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AnalyticsBrowser } from '@segment/analytics-next'
import { getAccount } from '@wagmi/core'
import { createContext, useContext } from 'react'
import { EXCLUDED_ADDRESSES } from '@constants/blacklist'

import { isBlacklisted } from '@/utils/isBlacklisted'
import { screenAddress } from '@/utils/screenAddress'

const writeKey = process.env.NEXT_PUBLIC_SEGMENT_WRITE_KEY

Expand All @@ -12,28 +14,21 @@ export const analytics = AnalyticsBrowser.load(
{ initialPageview: false }
)

export const segmentAnalyticsEvent = (eventTitle: string, eventData: {}) => {
export const segmentAnalyticsEvent = (
eventTitle: string,
eventData: {},
screen: boolean = false
) => {
const defaultOptions = { context: { ip: '0.0.0.0' } }

const { address } = getAccount()

if (EXCLUDED_ADDRESSES.includes(address)) {
if (isBlacklisted(address)) {
document.body = document.createElement('body')
} else {
fetch('https://screener.s-b58.workers.dev/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ address: address }),
})
.then((response) => response.json())
.then((data) => {
if (data.block) {
document.body = document.createElement('body')
}
})
.catch((error) => console.error('Error:', error))
if (screen) {
screenAddress(address)
}
}

const enrichedEventData = {
Expand Down
12 changes: 12 additions & 0 deletions packages/synapse-interface/contexts/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
fetchMetisPrice,
fetchSynPrices,
} from '@/slices/priceDataSlice'
import { isBlacklisted } from '@/utils/isBlacklisted'
import { screenAddress } from '@/utils/screenAddress'

const WalletStatusContext = createContext(undefined)

Expand Down Expand Up @@ -95,6 +97,16 @@ export const UserProvider = ({ children }) => {
})()
}, [chain, address, isClient])

useEffect(() => {
if (address) {
if (!isBlacklisted(address)) {
screenAddress(address)
} else {
document.body = document.createElement('body')
}
}
}, [address])

return (
<WalletStatusContext.Provider value={null}>
{children}
Expand Down
20 changes: 12 additions & 8 deletions packages/synapse-interface/pages/state-managed-bridge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,18 @@ const StateManagedBridge = () => {
}

const executeBridge = async () => {
segmentAnalyticsEvent(`[Bridge] initiates bridge`, {
address,
originChainId: fromChainId,
destinationChainId: toChainId,
inputAmount: debouncedFromValue,
expectedReceivedAmount: bridgeQuote.outputAmountString,
slippage: bridgeQuote.exchangeRate,
})
segmentAnalyticsEvent(
`[Bridge] initiates bridge`,
{
address,
originChainId: fromChainId,
destinationChainId: toChainId,
inputAmount: debouncedFromValue,
expectedReceivedAmount: bridgeQuote.outputAmountString,
slippage: bridgeQuote.exchangeRate,
},
true
)
const currentTimestamp: number = getTimeMinutesFromNow(0)
dispatch(
addPendingBridgeTransaction({
Expand Down
22 changes: 13 additions & 9 deletions packages/synapse-interface/pages/swap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,19 @@ const StateManagedSwap = () => {
`Initiating swap from ${swapFromToken.symbol} to ${swapToToken.symbol} on ${currentChainName}`,
{ id: 'swap-in-progress-popup', duration: Infinity }
)
segmentAnalyticsEvent(`[Swap] initiates swap`, {
address,
chainId: swapChainId,
swapFromToken: swapFromToken.symbol,
swapToToken: swapToToken.symbol,
inputAmount: swapFromValue,
expectedReceivedAmount: swapQuote.outputAmountString,
exchangeRate: swapQuote.exchangeRate,
})
segmentAnalyticsEvent(
`[Swap] initiates swap`,
{
address,
chainId: swapChainId,
swapFromToken: swapFromToken.symbol,
swapToToken: swapToToken.symbol,
inputAmount: swapFromValue,
expectedReceivedAmount: swapQuote.outputAmountString,
exchangeRate: swapQuote.exchangeRate,
},
true
)
try {
const wallet = await getWalletClient({
chainId: swapChainId,
Expand Down
Loading

0 comments on commit 1539364

Please sign in to comment.