Skip to content

Commit

Permalink
refactor: ID-2589 Add json rpc referrer as optional param and set on …
Browse files Browse the repository at this point in the history
…game bridge (#2332)
  • Loading branch information
imx-mikhala authored Oct 18, 2024
1 parent cdd7838 commit f8a7134
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/passport/telegram-mini-app/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const passportInstance = new passport.Passport({
logoutRedirectUri: process.env.NEXT_PUBLIC_LOGOUT_REDIRECT_URI || "",
audience: "platform_api",
scope: "openid offline_access email transact",
// Enable crossSdkBridge to enable pre-approved transactions
// Set crossSdkBridgeEnabled to enable pre-approved transactions
crossSdkBridgeEnabled: true,
});
// #enddoc passport-telegram-mini-app-configuration
Expand Down
1 change: 1 addition & 0 deletions packages/game-bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ window.callFunction = async (jsonData: string) => {
redirectUri: redirect ?? redirectUri,
logoutRedirectUri: request?.logoutRedirectUri,
crossSdkBridgeEnabled: true,
jsonRpcReferrer: 'http://imtblgamesdk.local',
logoutMode,
};
}
Expand Down
4 changes: 4 additions & 0 deletions packages/passport/sdk/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export class PassportConfiguration {

readonly crossSdkBridgeEnabled: boolean;

readonly jsonRpcReferrer: string;

readonly forceScwDeployBeforeMessageSignature: boolean;

readonly popupOverlayOptions: PopupOverlayOptions;
Expand All @@ -58,6 +60,7 @@ export class PassportConfiguration {
baseConfig,
overrides,
crossSdkBridgeEnabled,
jsonRpcReferrer,
forceScwDeployBeforeMessageSignature,
popupOverlayOptions,
...oidcConfiguration
Expand All @@ -69,6 +72,7 @@ export class PassportConfiguration {
this.oidcConfiguration = oidcConfiguration;
this.baseConfig = baseConfig;
this.crossSdkBridgeEnabled = crossSdkBridgeEnabled || false;
this.jsonRpcReferrer = jsonRpcReferrer || '';
this.forceScwDeployBeforeMessageSignature = forceScwDeployBeforeMessageSignature || false;
this.popupOverlayOptions = popupOverlayOptions || {
disableGenericPopupOverlay: false,
Expand Down
6 changes: 6 additions & 0 deletions packages/passport/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export interface PassportModuleConfiguration
*/
crossSdkBridgeEnabled?: boolean;

/**
* Optional referrer URL to be sent with JSON-RPC requests.
* If specified, this value will be passed as the referrer in fetch options.
*/
jsonRpcReferrer?: string;

/**
* Options for disabling the Passport popup overlays.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/passport/sdk/src/zkEvm/zkEvmProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ export class ZkEvmProvider implements Provider {
this.#guardianClient = guardianClient;
this.#passportEventEmitter = passportEventEmitter;

if (config.crossSdkBridgeEnabled) {
if (config.jsonRpcReferrer) {
// StaticJsonRpcProvider by default sets the referrer as "client".
// On Unreal 4 this errors as the browser used is expecting a valid URL.
this.#rpcProvider = new StaticJsonRpcProvider({
url: this.#config.zkEvmRpcUrl,
fetchOptions: { referrer: 'http://imtblgamesdk.local' },
fetchOptions: { referrer: config.jsonRpcReferrer },
});
} else {
this.#rpcProvider = new StaticJsonRpcProvider(this.#config.zkEvmRpcUrl);
Expand Down

0 comments on commit f8a7134

Please sign in to comment.