-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(synapse-interface): Dest address screener middleware (#2870)
* Adds destination address middleware screening check * Changes screenAddress to async/await * Moves bl check into screenAddress
- Loading branch information
1 parent
99f3c9a
commit df288f5
Showing
7 changed files
with
73 additions
and
32 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,42 @@ | ||
import { Address } from 'viem' | ||
|
||
import { GlobalEventEmitter } from '@/utils/globalEventEmitter' | ||
import { DISCORD_URL } from '@/constants/urls' | ||
import { GlobalEventEmitter } from '@/utils/globalEventEmitter' | ||
import { isBlacklisted } from '@/utils/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>.`, | ||
}, | ||
}) | ||
|
||
GlobalEventEmitter.dispatchEvent(event) | ||
} | ||
}) | ||
.catch((error) => console.error('Error:', error)) | ||
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) | ||
return true | ||
} | ||
return false | ||
} catch (error) { | ||
console.error('Error:', error) | ||
return false | ||
} | ||
} |