Skip to content

Commit

Permalink
fix: various issues with TLink
Browse files Browse the repository at this point in the history
- Since tokenscript viewer iframe is embedded in a null origin iframe
  it inherits its security origin. So we must use "*" origin when
  showing the tlink viewers.
- Initialise default view controller to avoid error when putting
  user input.
  • Loading branch information
micwallace committed Oct 18, 2024
1 parent 9d423c0 commit 59ab35e
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion javascript/engine-js/src/AbstractEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const DEFAULT_CONFIG: IEngineConfig = {
ipfsGateway: 'https://smart-token-labs-demo-server.mypinata.cloud/ipfs/',
noLocalStorage: false,
trustedKeys: [],
viewerOrigin: document ? document.location.origin : "*"
};

/**
Expand All @@ -18,7 +19,7 @@ export abstract class AbstractTokenScriptEngine implements ITokenScriptEngine {
// TODO: Should we pass in a function or a constructor, dunno
constructor(public getWalletAdapter: () => Promise<IWalletAdapter>, public readonly config?: IEngineConfig) {
this.repo = new Repo(this)

if (this.config) {
this.config = {
...DEFAULT_CONFIG,
Expand Down
1 change: 1 addition & 0 deletions javascript/engine-js/src/IEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IEngineConfig {
noLocalStorage?: boolean;
trustedKeys?: TrustedKey[]; // Define signing keys which are always valid
txValidationCallback?: (txInfo: ITxValidationInfo) => boolean | Promise<boolean>;
viewerOrigin?: string;
}

export enum ScriptSourceType {
Expand Down
2 changes: 1 addition & 1 deletion javascript/engine-js/src/view/TokenViewData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class TokenViewData {
const walletAddress = '${await walletAdapter.getCurrentWalletAddress()}';
const rpcURL = "${rpcURLs?.[0] ?? ''}";
const chainID = "${tokenData.chainId}";
const engineOrigin = "${document.location.origin}";
const engineOrigin = "${this.tokenScript.getEngine().config.viewerOrigin}";
// Injected card SDK
${CARD_SDK_V1}
Expand Down
3 changes: 2 additions & 1 deletion javascript/tokenscript-viewer/src/components/app/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ export class AppRoot {
// TODO: This is temporarily disabled to add support for contracts not defined in the tokenscript
return true;
//return this.confirmTxPopover.confirmTransaction(txInfo);
}
},
viewerOrigin: this.viewerType.indexOf("tlink") === 0 ? "*" : document.location.origin
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ export class TlinkCardViewer {
// The card is already loaded, we only need to update other card buttons
if (reloadInfoView || !this.mainViewController) {
const mainViewBinding = new ViewBinding(this.mainCardView, this.showToast);
this.mainViewController = this.tokenScript.getViewController(mainViewBinding);
this.tokenScript.setViewBinding(mainViewBinding);
this.mainViewController = this.tokenScript.getViewController();
mainViewBinding.setViewController(this.mainViewController);
this.mainViewController.showOrExecuteCard(this.mainCard, undefined);
}
Expand Down

0 comments on commit 59ab35e

Please sign in to comment.