Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
36 changes: 24 additions & 12 deletions djed-sdk/src/web3.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import Web3 from "web3";

export const getWeb3 = (BLOCKCHAIN_URI) =>
new Promise((resolve, reject) => {
if (window.ethereum) {
try {
const web3 = new Web3(BLOCKCHAIN_URI);
resolve(web3);
} catch (error) {
reject(error);
}
} else {
reject("Please install Metamask");
export const getWeb3 = async (URI) => {
if (typeof window !== "undefined" && window.ethereum) {
try {
const web3 = new Web3(window.ethereum);

// Request account access (important)
await window.ethereum.request({ method: "eth_requestAccounts" });

return web3;
} catch (error) {
const msg = error?.code === 4001
? "User denied account access"
: "Failed to initialize wallet provider";
console.error(msg, error);
throw error;
Comment thread
Rav1Chauhan marked this conversation as resolved.
}
});
}

// Fallback to RPC
if (!URI) {
throw new Error("No injected provider found and no fallback URI supplied.");
}
// Fallback to RPC
return new Web3(new Web3.providers.HttpProvider(URI));
Comment on lines +3 to +26

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# 1. Check if djed-sdk/dist files are tracked by git
echo "=== Checking if djed-sdk/dist files are tracked by git ==="
git -C djed-sdk ls-files dist/ 2>/dev/null | head -20

# 2. Confirm what entrypoints package.json exposes
echo ""
echo "=== Checking djed-sdk/package.json entrypoints ==="
fd "package.json" djed-sdk --max-depth 2 --exec cat {}

# 3. Show the stale provider logic still in dist
echo ""
echo "=== Searching for BLOCKCHAIN_URI or old Web3 logic in dist ==="
rg -n "BLOCKCHAIN_URI\|new Web3\(BLOCKCHAIN_URI" djed-sdk/dist/ 2>/dev/null || echo "No matches found"

Repository: DjedAlliance/StablePay

Length of output: 836


🏁 Script executed:

#!/bin/bash
# Check the actual content of dist files to see if they're truly stale
echo "=== Content of dist/esm/index.js ==="
cat djed-sdk/dist/esm/index.js

echo ""
echo "=== Content of dist/umd/index.js ==="
cat djed-sdk/dist/umd/index.js

# Also check git history to see when dist was last updated
echo ""
echo "=== Recent git commits touching dist files ==="
git log --oneline -n 10 -- djed-sdk/dist/

Repository: DjedAlliance/StablePay

Length of output: 50378


Dist bundles in djed-sdk/dist/ are stale and ship the old broken implementation.

The dist files (djed-sdk/dist/esm/index.js and djed-sdk/dist/umd/index.js) still contain the original broken getWeb3 implementation that directly passes BLOCKCHAIN_URI to Web3(BLOCKCHAIN_URI), whereas the fixed source code properly requests account access and uses window.ethereum. Since package.json points to these dist files as the main entrypoints ("main": "dist/umd/index.js", "module": "dist/esm/index.js"), consumers will receive the broken code from the published package regardless of this source fix.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@djed-sdk/src/web3.js` around lines 3 - 19, The published bundle still
contains the old getWeb3 implementation, so rebuild and overwrite the dist
artifacts with the fixed source: run the project build step (so
dist/esm/index.js and dist/umd/index.js are regenerated) ensuring the exported
getWeb3 function in the dist matches the source that uses window.ethereum and
eth_requestAccounts; verify package.json's "main" and "module" still point to
dist/umd/index.js and dist/esm/index.js and then commit the regenerated files
(or update the build/publish pipeline to run the build before publishing) so
consumers receive the corrected implementation.

Comment thread
Rav1Chauhan marked this conversation as resolved.
};
1 change: 1 addition & 0 deletions stablepay-sdk/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# macOS specific files
.DS_Store

dist/
1 change: 0 additions & 1 deletion stablepay-sdk/dist/umd/index.js.map

This file was deleted.

28 changes: 28 additions & 0 deletions stablepay-sdk/dist/umd/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>StablePay Test</title>
<script src="./index.js"></script>
</head>
<body>
<h2>Test Web3 Init</h2>
<button onclick="testWeb3()">Connect Wallet</button>

<script>
async function testWeb3() {
if (typeof window.ethereum === "undefined") {
alert("MetaMask not installed");
return;
}

try {
const web3 = await StablePay.getWeb3("https://mainnet.infura.io/v3/YOUR_KEY");
console.log("Web3 instance:", web3);
alert("Connected! Check console.");
} catch (err) {
console.error(err);
}
}
</script>
</body>
</html>
4 changes: 2 additions & 2 deletions stablepay-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.