Skip to content

Commit

Permalink
fix: update webwallet for offchain sessions changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bluecco committed Apr 2, 2024
1 parent d44eaac commit 2cd3220
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/connectors/webwallet/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ export const RPC_NODE_URL_TESTNET =

export const RPC_NODE_URL_MAINNET =
"https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.6"

export const OFFCHAIN_SESSION_ENTRYPOINT = "use_offchain_session"
3 changes: 2 additions & 1 deletion src/connectors/webwallet/starknetWindowObject/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
SIGN_MESSAGE_POPUP_HEIGHT,
SIGN_MESSAGE_POPUP_WIDTH,
} from "../helpers/popupSizes"
import { OFFCHAIN_SESSION_ENTRYPOINT } from "../constants"

class UnimplementedSigner implements SignerInterface {
async getPubKey(): Promise<string> {
Expand Down Expand Up @@ -64,7 +65,7 @@ export class MessageAccount extends Account implements AccountInterface {
if (
Array.isArray(calls) &&
calls[0] &&
calls[0].entrypoint === "use_offchain_session"
calls[0].entrypoint === OFFCHAIN_SESSION_ENTRYPOINT
) {
setPopupOptions({
width: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
SIGN_MESSAGE_POPUP_HEIGHT,
SIGN_MESSAGE_POPUP_WIDTH,
} from "../helpers/popupSizes"
import { OFFCHAIN_SESSION_ENTRYPOINT } from "../constants"

export const userEventHandlers: WalletEvents[] = []

Expand Down Expand Up @@ -77,7 +78,7 @@ export const getArgentStarknetWindowObject = (
if (
Array.isArray(calls) &&
calls[0] &&
calls[0].entrypoint === "use_offchain_session"
calls[0].entrypoint === OFFCHAIN_SESSION_ENTRYPOINT
) {
setPopupOptions({
width: 1,
Expand All @@ -86,9 +87,7 @@ export const getArgentStarknetWindowObject = (
atLeftBottom: true,
})
}
const hash = await proxyLink.addInvokeTransaction.mutate(
(call.params as any).calls,
)
const hash = await proxyLink.addInvokeTransaction.mutate(calls)

return { transaction_hash: hash }
}
Expand Down
28 changes: 23 additions & 5 deletions src/types/window.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OFFCHAIN_SESSION_ENTRYPOINT } from "../connectors/webwallet/constants"
import type { InvokeFunctionResponse, Signature } from "starknet"
import { z } from "zod"

Expand Down Expand Up @@ -164,16 +165,33 @@ export type IframeMethods = {
connect: () => void
}

export const OffchainSessionDetailsSchema = z.object({
nonce: bignumberishSchema,
maxFee: bignumberishSchema.optional(),
version: z.string(),
})

export const RpcCallSchema = z
.object({
contract_address: z.string(),
entrypoint: z.string(),
calldata: z.array(bignumberishSchema).optional(),
offchainSessionDetails: OffchainSessionDetailsSchema.optional(),
})
.transform(({ contract_address, entrypoint, calldata }) => ({
contractAddress: contract_address,
entrypoint,
calldata: calldata || [],
}))
.transform(
({ contract_address, entrypoint, calldata, offchainSessionDetails }) =>
entrypoint === OFFCHAIN_SESSION_ENTRYPOINT
? {
contractAddress: contract_address,
entrypoint,
calldata: calldata || [],
offchainSessionDetails: offchainSessionDetails || undefined,
}
: {
contractAddress: contract_address,
entrypoint,
calldata: calldata || [],
},
)

export const RpcCallsArraySchema = z.array(RpcCallSchema).nonempty()

0 comments on commit 2cd3220

Please sign in to comment.