Skip to content

Commit

Permalink
feat: txs working
Browse files Browse the repository at this point in the history
  • Loading branch information
stephancill committed Jul 16, 2024
1 parent a0820a6 commit 9f08e6f
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 41 deletions.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion front/.env.local.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
NEXT_PUBLIC_STACKUP_BUNDLER_API_KEY=""
NEXT_PUBLIC_RPC_ENDPOINT=""
ETHERSCAN_API_KEY=""
NEXT_PUBLIC_FACTORY_CONTRACT_ADDRESS="0xDD0f9cB4Cf53d28b976C13e7ee4a169F841924c0"
NEXT_PUBLIC_FACTORY_CONTRACT_ADDRESS="0xE4e6BF50E1fb02b323ca855dF0d8D76a75290FfC"
RELAYER_PRIVATE_KEY=""
43 changes: 38 additions & 5 deletions front/src/app/connect/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
RPCRequest,
RPCResponse,
} from "../../utils/cipher";
import { smartWallet } from "../../libs/smart-wallet";

const keyManager = new SCWKeyManager();

Expand All @@ -35,6 +36,12 @@ async function sendEncryptedMessage({ id, content }: { id: string; content: any
);
}

function closePopup() {
const parent = window.self;
parent.opener = window.self;
parent.close();
}

export default function Page() {
const [messages, setMessages] = useState<any[]>([]);
const me = useMe();
Expand Down Expand Up @@ -71,21 +78,47 @@ export default function Page() {
const peerPublicKey = await importKeyFromHexString("public", m.data.sender);
await keyManager.setPeerPublicKey(peerPublicKey);
const accountResult = await me.get();

const chains: Record<number, string> = {};
if (smartWallet.client.chain) {
chains[smartWallet.client.chain.id] = smartWallet.client.chain.rpcUrls.default.http[0];
}

const message = {
result: { value: accountResult?.account },
data: {
chains,
},
};
await sendEncryptedMessage({ id: m.data.id, content: message });
await sendEncryptedMessage({
id: m.data.id,
content: message,
});

var daddy = window.self;
daddy.opener = window.self;
daddy.close();
closePopup();
} else if (decrypted && "action" in decrypted) {
smartWallet.init();
if (!decrypted.action.params) {
console.error("No params in action");
return;
}

const result = await walletConnect.handleRequest({
method: decrypted.action.method,
origin: m.origin,
params: decrypted.action.params as any,
});
await sendEncryptedMessage({ id: m.data.id, content: result });

const message = {
result: { value: result },
};

await sendEncryptedMessage({
id: m.data.id,
content: message,
});

closePopup();
}
},
false,
Expand Down
7 changes: 4 additions & 3 deletions front/src/components/WCSendTransactionModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ export default function WCSendTransactionModal({ params, origin, onSuccess }: Pr
const { maxFeePerGas, maxPriorityFeePerGas } = await smartWallet.client.estimateFeesPerGas();

const value = params?.value ? BigInt(params.value) : BigInt(0);
const data = params?.data ? params.data : "0x";

const userOp = await builder.buildUserOp({
calls: [
{
dest: params.to,
value,
data: params.data,
data,
},
],
maxFeePerGas: maxFeePerGas as bigint,
Expand Down Expand Up @@ -224,14 +225,14 @@ export default function WCSendTransactionModal({ params, origin, onSuccess }: Pr
</Flex>

<Flex direction={"column"} gap="3">
{error && (
{error && error instanceof Error && (
<Callout.Root
style={{ maxHeight: "150px", overflowY: "scroll", wordBreak: "break-word" }}
>
<Callout.Icon>
<InfoCircledIcon />
</Callout.Icon>
<Callout.Text>{error}</Callout.Text>
<Callout.Text>{error.message}</Callout.Text>
</Callout.Root>
)}
<Button variant="outline" size="3" type="submit">
Expand Down
2 changes: 1 addition & 1 deletion front/src/libs/wallet-connect/config/EIP155.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export enum EIP155Method {
SignTypedDataV4 = "eth_signTypedData_v4",
EthSendRawTransaction = "eth_sendRawTransaction",
EthSendTransaction = "eth_sendTransaction",
// SwitchChain = "wallet_switchEthereumChain",
SwitchChain = "wallet_switchEthereumChain",
// AddChain = "wallet_addEthereumChain",
}

Expand Down
15 changes: 10 additions & 5 deletions front/src/libs/wallet-connect/service/wallet-connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,14 @@ class WalletConnect extends EventEmitter {

public async handleRequest(
request: Omit<Parameters<typeof this._jsonRpcEventRouter>[0], "onSuccess" | "onReject">,
): Promise<{ result: any; jsonrpc: string }> {
): Promise<any> {
return new Promise((resolve, reject) => {
this._jsonRpcEventRouter({
method: request.method,
params: request.params,
origin: request.origin,
onSuccess: async (hash) => {
const response = { result: hash, jsonrpc: "2.0" };
resolve(response);
onSuccess: async (result) => {
resolve(result);
},
onReject: async () => {
const response = {
Expand Down Expand Up @@ -269,7 +268,7 @@ class WalletConnect extends EventEmitter {
method: string;
params: any[];
origin: string;
onSuccess: (hash: Hash) => void;
onSuccess: (args: any) => void;
onReject: () => Promise<void>;
}) {
switch (method) {
Expand All @@ -282,6 +281,12 @@ class WalletConnect extends EventEmitter {
} as EthSendEventPayload);
return null;

case EIP155Method.SwitchChain: {
// emit switch chain event
onSuccess(null);
return null;
}

default:
this.emit(WCEvent.MethodNotSupported, method);
return null;
Expand Down

0 comments on commit 9f08e6f

Please sign in to comment.