-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add asigna iframe connect (#400)
* added integration with Asigna via iframe * changed asigna provider data * fixed check for asigna iframe * chore: update lint errors * chore: add changeset --------- Co-authored-by: jeffrystone <[email protected]> Co-authored-by: janniks <[email protected]>
- Loading branch information
1 parent
a2939ca
commit d6ea424
Showing
4 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@stacks/connect-ui': minor | ||
'@stacks/connect': minor | ||
--- | ||
|
||
Add iframe capable Asigna provider. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const source = 'asigna-stx'; | ||
|
||
const generateCall = (payload: string, key: string) => { | ||
return new Promise(res => { | ||
function listener(message: MessageEvent<any>) { | ||
if (message.data.source === source && message.data[key]) { | ||
res(message.data[key]); | ||
window.removeEventListener('message', listener); | ||
} | ||
} | ||
window.addEventListener('message', listener); | ||
window.top.postMessage(generateAsignaMessage(payload, key), '*'); | ||
}); | ||
}; | ||
|
||
const AsignaIframeProvider = { | ||
authenticationRequest: async (payload: string) => { | ||
return generateCall(payload, 'authenticationRequest'); | ||
}, | ||
transactionRequest: async (payload: string) => { | ||
return generateCall(payload, 'transactionRequest'); | ||
}, | ||
}; | ||
const generateAsignaMessage = (payload: string, key: string) => { | ||
return { source, [key]: payload }; | ||
}; | ||
|
||
export const initializeAsignaProvider = () => { | ||
const isAsignaIframe = !!window.top && document.referrer.endsWith('.asigna.io/'); | ||
if (isAsignaIframe) { | ||
window['AsignaProvider'] = AsignaIframeProvider; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters