-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate all Send Addresses against stellar.expert's list of maliciou…
…s/unsafe addresses (#245) * Validate all Send Addresses against stellar.expert's list of malicious/unsafe addresses * remove debugger * no need to remove space * forgot to remove ts nocheck * move flaggedAccounts to redux and address UI issues * Rename warning message component * only show "malicious" warning in case it's both "unsafe" && "malicious" * default to the localStorage and replace with API if applicable * matching error message spacing to createTransaction * update UI of warning messages * update stellar.expert url
- Loading branch information
Showing
13 changed files
with
1,142 additions
and
483 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
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
19 changes: 19 additions & 0 deletions
19
src/components/SendTransaction/WarningMessages/AccountIsUnsafe.tsx
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,19 @@ | ||
import React from "react"; | ||
|
||
import { InfoBlock, InfoBlockVariant } from "components/basic/InfoBlock"; | ||
|
||
export const AccountIsUnsafe = () => ( | ||
<InfoBlock variant={InfoBlockVariant.warning}> | ||
<p> | ||
The account you’re sending to is tagged as <strong>#unsafe</strong> on{" "} | ||
<a | ||
href="https://stellar.expert/directory" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
stellar.expert’s directory | ||
</a> | ||
. Proceed with caution. | ||
</p> | ||
</InfoBlock> | ||
); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit"; | ||
|
||
import { | ||
FLAGGED_ACCOUNT_STORAGE_ID, | ||
FLAGGED_ACCOUNT_DATE_STORAGE_ID, | ||
} from "constants/settings"; | ||
import { getFlaggedAccounts } from "helpers/getFlaggedAccounts"; | ||
import { ActionStatus, FlaggedAccounts } from "types/types.d"; | ||
|
||
const initialState: FlaggedAccounts = { | ||
data: [{ address: "", tags: [""] }], | ||
status: undefined, | ||
}; | ||
|
||
export const fetchFlaggedAccountsAction = createAsyncThunk( | ||
"action/fetchFlaggedAccountsAction", | ||
async () => { | ||
let accounts; | ||
const date = new Date(); | ||
const time = date.getTime(); | ||
const sevenDaysAgo = time - 7 * 24 * 60 * 60 * 1000; | ||
const flaggedAccountsCacheDate = Number( | ||
localStorage.getItem(FLAGGED_ACCOUNT_DATE_STORAGE_ID), | ||
); | ||
|
||
accounts = JSON.parse( | ||
localStorage.getItem(FLAGGED_ACCOUNT_STORAGE_ID) || "[]", | ||
); | ||
|
||
// if flaggedAccounts were last cached over seven days ago, make the request | ||
// flaggedAccountsCacheDate is coerced to 0 if not found in storage | ||
if (flaggedAccountsCacheDate < sevenDaysAgo) { | ||
try { | ||
accounts = await getFlaggedAccounts(); | ||
// store the accounts plus the date we've acquired them | ||
localStorage.setItem( | ||
FLAGGED_ACCOUNT_STORAGE_ID, | ||
JSON.stringify(accounts), | ||
); | ||
localStorage.setItem(FLAGGED_ACCOUNT_DATE_STORAGE_ID, time.toString()); | ||
} catch (e) { | ||
console.error("Flagged account API did not respond"); | ||
} | ||
} | ||
|
||
return accounts; | ||
}, | ||
); | ||
|
||
const flaggedAccountsSlice = createSlice({ | ||
name: "flaggedAccounts", | ||
initialState, | ||
reducers: {}, | ||
extraReducers: (builder) => { | ||
builder.addCase( | ||
fetchFlaggedAccountsAction.pending, | ||
(state = initialState) => { | ||
state.status = ActionStatus.PENDING; | ||
}, | ||
); | ||
builder.addCase(fetchFlaggedAccountsAction.fulfilled, (state, action) => { | ||
state.status = ActionStatus.SUCCESS; | ||
state.data = action.payload; | ||
}); | ||
}, | ||
}); | ||
|
||
export const { reducer } = flaggedAccountsSlice; |
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,24 @@ | ||
const UNSAFE_ACCOUNTS_URL = | ||
"https://api.stellar.expert/explorer/directory?limit=20000000&tag[]=malicious&tag[]=unsafe"; | ||
// setting limit very high as there doesn't appear to be a better way to get all entries from API | ||
const RESPONSE_TIMEOUT = 5000; | ||
// if API doesn't respond in this amount of time, we'll cancel the request | ||
|
||
export const getFlaggedAccounts = async () => { | ||
const controller = new AbortController(); | ||
const timeoutId = setTimeout(() => controller.abort(), RESPONSE_TIMEOUT); | ||
|
||
const flaggedAccountsRes = await fetch(UNSAFE_ACCOUNTS_URL, { | ||
signal: controller.signal, | ||
}); | ||
clearTimeout(timeoutId); | ||
const flaggedAccountsJson = await flaggedAccountsRes.json(); | ||
|
||
const { | ||
_embedded: { records: unsafeAccountsData }, | ||
} = flaggedAccountsJson; | ||
|
||
return unsafeAccountsData.map( | ||
({ address, tags }: { address: string; tags: [] }) => ({ address, tags }), | ||
); | ||
}; |
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
Oops, something went wrong.