Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for high spam scores #1088 and lock wallet #1089 #1092

Merged
merged 21 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
023ebe3
Use renovate for dependency updates (#1054)
tackley Jun 26, 2023
c034ed0
removed as *[bot] is not accepted by AWS (#1055)
kim0 Jun 26, 2023
e5af0f3
Update all non-major dependencies (#1057)
renovate[bot] Jun 26, 2023
7f25f2b
Pin dependencies (#1056)
renovate[bot] Jun 26, 2023
216df15
Update all non-major dependencies (#1063)
renovate[bot] Jun 27, 2023
0dc1969
Update Node.js to v18.16.1 (#1059)
renovate[bot] Jun 27, 2023
19064f0
Revert "Update Node.js to v18.16.1 (#1059)"
mrose17 Jun 27, 2023
184d180
this is what should have happened (#1070)
mrose17 Jun 27, 2023
0e195d3
Update dependency react-i18next to v13 (#1060)
renovate[bot] Jun 27, 2023
9c60d6f
Address word-wrap audit warning (#1073)
tackley Jun 29, 2023
2efccfb
reduce impact of web3 dependencies on non-web3 users (#1066)
hadiamjad Jun 29, 2023
f1b1e66
removed short-circuit code
hadiamjad Jun 29, 2023
248351a
removed short-circuit code
hadiamjad Jun 29, 2023
c13a89a
Merge branch 'main' into abdul-sol-nft-gating
hadiamjad Jun 29, 2023
abc5328
fixed dynamic hexilify for solana
hadiamjad Jun 29, 2023
ac86f8b
phantom fallback option in solana
hadiamjad Jun 30, 2023
657d04c
Merge branch 'dev' into abdul-sol-nft-gating
hadiamjad Jun 30, 2023
83f0509
phantom wallet support for solana
hadiamjad Jun 30, 2023
fe62620
fix for high spam scores #1088 and lock wallet #1089
hadiamjad Jul 5, 2023
675e95a
fix for high spam scores #1088 and lock wallet #1089
hadiamjad Jul 5, 2023
a88d60c
Merge branch 'dev' into abdul-sol-nft-gating
hadiamjad Jul 5, 2023
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
83 changes: 61 additions & 22 deletions src/components/web3/SelectableImageList.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { useEffect, useState } from "react";
import { Dispatch } from "react";
import noNftImage from "../../images/no-nft-image.png";

interface Item {
imageUrl: string;
name?: string;
collection?: {
collection_id: string;
name: string;
image_url: string;
spam_score: number;
};
}

interface Props {
Expand All @@ -17,30 +24,62 @@ export const SelectableImageList: React.FC<Props> = ({
selectedIdxs,
onToggleSelection,
}) => {
const showCheckbox = items.some(
(item) => item.collection !== undefined && item.collection.spam_score > 80
);

const [showSpamItems, setShowSpamItems] = useState(false);

const filteredItems = showSpamItems
? items
: items.filter((item) => {
if (item.collection?.spam_score !== undefined) {
return item.collection.spam_score < 80;
}
return true;
});

const onToggleSpamItems = () => {
setShowSpamItems(!showSpamItems);
};

return (
<div css={{ display: "flex", flexWrap: "wrap" }}>
{items.map((item, idx) => (
<div
key={idx}
onClick={() => onToggleSelection(idx)}
css={{ padding: "5px 5px 5px 0" }}
title={item.name}
>
<img
title={item.name}
height={167}
width={167}
src={item.imageUrl ? item.imageUrl : noNftImage}
css={{
border: `5px solid ${
selectedIdxs.includes(idx) ? "white" : "transparent"
}`,
}}
alt="item"
/>
{}
<div css={{ display: "flex", flexDirection: "column" }}>
{showCheckbox && (
<div css={{ marginBottom: "10px" }}>
<label>
<input
type="checkbox"
checked={showSpamItems}
onChange={onToggleSpamItems}
/>
{showSpamItems ? "Show All NFTs" : "Show NFTs with Less Spam Score"}
</label>
</div>
))}
)}
<div css={{ display: "flex", flexWrap: "wrap" }}>
{filteredItems.map((item, idx) => (
<div
key={idx}
onClick={() => onToggleSelection(idx)}
css={{ padding: "5px 5px 5px 0" }}
title={item.name}
>
<img
title={item.name}
height={167}
width={167}
src={item.imageUrl ? item.imageUrl : noNftImage}
css={{
border: `5px solid ${
selectedIdxs.includes(idx) ? "white" : "transparent"
}`,
}}
alt="item"
/>
</div>
))}
</div>
</div>
);
};
2 changes: 1 addition & 1 deletion src/components/web3/StartCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const StartCall: React.FC<Props> = ({
setFeedbackMessage("identifier_fetch_error");
});
}
}, [web3Address]);
}, [web3Address, web3Account]);

const onStartCall = async () => {
if (!web3Address) return;
Expand Down
31 changes: 13 additions & 18 deletions src/components/web3/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ export const web3Login = async (): Promise<string> => {
};

export const web3LoginSol = async (): Promise<string> => {
try{
try {
const result = await window.braveSolana.connect();
console.log("!!! allAddresses", result);
return result.publicKey.toBase58();
}catch{
const result = await window.phantom.solana.connect();
console.log("!!! allAddresses", result);
return result.publicKey.toBase58();
} catch {
const result = await window.phantom.solana.connect();
console.log("!!! allAddresses", result);
return result.publicKey.toBase58();
}
};

Expand Down Expand Up @@ -99,12 +99,6 @@ export const web3NFTs = async (address: string): Promise<NFT[]> => {

const result: NFT[] = [];
nfts.nfts.forEach((nft: any) => {
if (
"spam_score" in nft.collection &&
typeof nft.collection.spam_score === "number" &&
nft.collection.spam_score >= 80
)
return;
result.push({
image_url: nft.previews?.image_small_url
? nft.previews.image_small_url
Expand All @@ -114,6 +108,7 @@ export const web3NFTs = async (address: string): Promise<NFT[]> => {
collection_id: nft.collection?.collection_id,
name: nft.collection?.name,
image_url: nft.collection?.image_url,
spam_score: nft.collection.spam_score,
},
});
});
Expand Down Expand Up @@ -272,9 +267,9 @@ export const web3SolProve = async (
const payloadBytes = new TextEncoder().encode(payload);
const { hexlify } = await import("ethers");
const hexPayload = hexlify(payloadBytes);
try{
try {
const { publicKey, signature } = await window.braveSolana.signMessage(
payloadBytes
payloadBytes
);
const result = {
method: "CAIP-122-json",
Expand All @@ -283,12 +278,12 @@ export const web3SolProve = async (
signature: Buffer.from(signature).toString("hex"),
payload: hexPayload,
},
};
};
return result;
}catch {
} catch {
const { publicKey, signature } = await window.phantom.solana.signMessage(
payloadBytes
);
);
const result = {
method: "CAIP-122-json",
proof: {
Expand All @@ -297,8 +292,8 @@ export const web3SolProve = async (
payload: hexPayload,
},
};
return result;

return result;
}
};

Expand Down
1 change: 1 addition & 0 deletions src/components/web3/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface NFT {
collection_id: string;
name: string;
image_url: string;
spam_score: number;
};
previews?: {
image_small_url: string;
Expand Down
27 changes: 15 additions & 12 deletions src/hooks/use-web3-call-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ export function useWeb3CallState(
});
};

window.ethereum?.on("accountsChanged", (accounts: string[]) => {
console.log("!!! ETH accountsChanged", accounts);
setWeb3Account("ETH");
setWeb3Address(accounts[0], "accountsChanged");
});
if (web3Account === "ETH") {
window.ethereum?.on("accountsChanged", (accounts: string[]) => {
console.log("!!! ETH accountsChanged", accounts);
setWeb3Account("ETH");
setWeb3Address(accounts[0], "accountsChanged");
});
}

try{

try {
window.braveSolana?.on("accountChanged", (account: any) => {
setWeb3Account("SOL");
if (account) {
Expand All @@ -89,12 +92,12 @@ export function useWeb3CallState(
console.log("!!! SOL accountChanged", account);
setWeb3Address(account, "accountsChanged");
}
});
}catch{
console.warn("!!! Brave Wallet does not exists")
});
} catch {
console.warn("!!! Brave Wallet does not exists");
}

try{
try {
window.phantom?.solana.on("accountChanged", (account: any) => {
setWeb3Account("SOL");
console.log(account);
Expand All @@ -106,8 +109,8 @@ export function useWeb3CallState(
setWeb3Address(account, "accountsChanged");
}
});
}catch {
console.warn("!!! Phantom Wallet does not exists")
} catch {
console.warn("!!! Phantom Wallet does not exists");
}

const joinCall = async (
Expand Down