-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
71 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/synapse-interface/store/destinationAddressMiddleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Middleware } from '@reduxjs/toolkit' | ||
|
||
import { screenAddress } from '@/utils/screenAddress' | ||
import { setDestinationAddress } from '@/slices/bridge/reducer' | ||
|
||
export const destinationAddressMiddleware: Middleware = | ||
(_store) => (next) => async (action) => { | ||
if (setDestinationAddress.match(action) && action.payload !== null) { | ||
const isRisky = await screenAddress(action.payload) | ||
if (isRisky) { | ||
return | ||
} | ||
} | ||
return next(action) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,41 @@ | ||
import { Address } from 'viem' | ||
|
||
import { GlobalEventEmitter } from '@/utils/globalEventEmitter' | ||
import { DISCORD_URL } from '@/constants/urls' | ||
import { isBlacklisted } from './isBlacklisted' | ||
|
||
const createRiskDetectedEvent = (address: Address | string) => { | ||
return new CustomEvent('riskDetected', { | ||
detail: { | ||
message: `This address ${address} has been flagged for being associated with illicit activities. If you think this is a mistake, please contact <a style="text-decoration: underline; text-underline-offset: 0.2em;" href=${DISCORD_URL} target="_blank" rel="noopener noreferrer">support</a>.`, | ||
}, | ||
}) | ||
} | ||
|
||
export const screenAddress = (address: Address | string) => { | ||
export const screenAddress = async ( | ||
address: Address | string | ||
): Promise<boolean> => { | ||
const url = `https://screener.omnirpc.io/fe/address/${address}` | ||
|
||
fetch(url, { | ||
method: 'GET', | ||
}) | ||
.then((response) => response.json()) | ||
.then(({ risk }) => { | ||
if (risk) { | ||
const event = new CustomEvent('riskDetected', { | ||
detail: { | ||
message: `This address has been flagged for being associated with illicit activities. If you think this is a mistake, please contact <a style="text-decoration: underline; text-underline-offset: 0.2em;" href=${DISCORD_URL} target="_blank" rel="noopener noreferrer">support</a>.`, | ||
}, | ||
}) | ||
if (isBlacklisted(address)) { | ||
const event = createRiskDetectedEvent(address) | ||
|
||
GlobalEventEmitter.dispatchEvent(event) | ||
return true | ||
} | ||
|
||
try { | ||
const response = await fetch(url, { method: 'GET' }) | ||
const { risk } = await response.json() | ||
|
||
if (risk) { | ||
const event = createRiskDetectedEvent(address) | ||
|
||
GlobalEventEmitter.dispatchEvent(event) | ||
} | ||
}) | ||
.catch((error) => console.error('Error:', error)) | ||
GlobalEventEmitter.dispatchEvent(event) | ||
return true | ||
} | ||
return false | ||
} catch (error) { | ||
console.error('Error:', error) | ||
return false | ||
} | ||
} |