diff --git a/.changeset/smart-dingos-train.md b/.changeset/smart-dingos-train.md new file mode 100644 index 00000000..9cdfd3dc --- /dev/null +++ b/.changeset/smart-dingos-train.md @@ -0,0 +1,6 @@ +--- +'@stacks/connect-ui': minor +'@stacks/connect': minor +--- + +Add iframe capable Asigna provider. diff --git a/packages/connect-ui/src/components/modal/modal.tsx b/packages/connect-ui/src/components/modal/modal.tsx index 7d99a4d9..ff6ab0ab 100644 --- a/packages/connect-ui/src/components/modal/modal.tsx +++ b/packages/connect-ui/src/components/modal/modal.tsx @@ -204,7 +204,7 @@ export class Modal { rel="noopener noreferrer" target="_blank" > - Install → + {provider.id === 'AsignaProvider' ? 'Open' : 'Install'} → )} diff --git a/packages/connect/src/asigna.ts b/packages/connect/src/asigna.ts new file mode 100644 index 00000000..87ef2176 --- /dev/null +++ b/packages/connect/src/asigna.ts @@ -0,0 +1,33 @@ +const source = 'asigna-stx'; + +const generateCall = (payload: string, key: string) => { + return new Promise(res => { + function listener(message: MessageEvent) { + 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; + } +}; diff --git a/packages/connect/src/providers.ts b/packages/connect/src/providers.ts index 006e0adb..459d1dfb 100644 --- a/packages/connect/src/providers.ts +++ b/packages/connect/src/providers.ts @@ -1,4 +1,7 @@ import { WebBTCProvider } from '@stacks/connect-ui'; +import { initializeAsignaProvider } from './asigna'; + +initializeAsignaProvider(); export const DEFAULT_PROVIDERS: WebBTCProvider[] = [ { @@ -25,10 +28,9 @@ export const DEFAULT_PROVIDERS: WebBTCProvider[] = [ }, { id: 'AsignaProvider', - name: 'Asigna', + name: 'Asigna Multisig', icon: 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIzMiIgaGVpZ2h0PSIzMiIgZmlsbD0ibm9uZSI+PHBhdGggZmlsbD0iIzAwMDEwMCIgZD0iTTAgMGgzMnYzMkgweiIvPjxwYXRoIGZpbGw9InVybCgjYSkiIGQ9Ik0xNS4xMSA1LjU1YTMgMyAwIDAgMC0xLjgyIDEuM2wtLjA1LjA4LS40My43Mi0uMDcuMTEtLjUuODUtLjA1LjA5LTEuMjkgMi4xOC0uMDQuMDctLjQ3LjgtLjA2LjEtLjQ2Ljc4LS4wNy4xMS0xLjYzIDIuNzYtLjA3LjExLS4zOC42Ni0uMDUuMDgtLjczIDEuMjQtLjM1LjYtLjQuNjctLjA1LjA5TDUuMSAyMC43bC0uMTEuMTgtLjE0LjIzLS4wNy4xMy0uMzMuNTUtLjA0LjA3di4wMWExLjI2IDEuMjYgMCAwIDAtLjE0LjQ3IDEuMzEgMS4zMSAwIDAgMCAxLjI0IDEuNGgxLjVsLjA1LS4wNi4wNC0uMDYuODctMS4yMS4wNS0uMDguNzctMS4wNy4wNS0uMDcuNC0uNTcuMDUtLjA2LjI0LS4zNGExLjUyIDEuNTIgMCAwIDEgMS4zOS0uNjIgMS41IDEuNSAwIDAgMSAuNjQuMiAxLjQ3IDEuNDcgMCAwIDEgLjczIDEuMjcgMS40NCAxLjQ0IDAgMCAxLS4yNy44NGwtLjYzLjg4LS4wNS4wNy0uMzIuNDUtLjA2LjA4LS4wOC4xMi0uMTIuMTYtLjA1LjA4aDIuMTNhMi4zMiAyLjMyIDAgMCAwIDEuNzctLjk2bDEuMTgtMS42My43Ny0xLjA4IDEuMy0xLjhhMS4yNCAxLjI0IDAgMCAxIC41NS0u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RoIGZpbGw9IiNmZmYiIGQ9Ik0xMi4yOSAyMS4wOGMwIC4yOS0uMDkuNTgtLjI3Ljg0bC0xLjMxIDEuODRIN2wyLjUyLTMuNTNhMS41NCAxLjU0IDAgMCAxIDIuMS0uMzZjLjQzLjI4LjY2Ljc0LjY2IDEuMloiLz48cGF0aCBmaWxsPSIjMDAwIiBkPSJNMTEuMTYgMjEuMjVhLjU2LjU2IDAgMCAxLS41Ny41NS41Ni41NiAwIDAgMS0uNTctLjU2LjU2LjU2IDAgMCAxIC41Ny0uNTUuNTYuNTYgMCAwIDEgLjU3LjU2WiIvPjxkZWZzPjxsaW5lYXJHcmFkaWVudCBpZD0iYSIgeDE9IjE1LjIzIiB4Mj0iMTkuMyIgeTE9IjI1Ljc4IiB5Mj0iNi4xMSIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPjxzdG9wIHN0b3AtY29sb3I9IiM2NTIyRjQiLz48c3RvcCBvZmZzZXQ9Ii41NSIgc3RvcC1jb2xvcj0iIzlCNkJGRiIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iI0E1ODVGRiIvPjwvbGluZWFyR3JhZGllbnQ+PGxpbmVhckdyYWRpZW50IGlkPSJiIiB4MT0iMjIuNTkiIHgyPSIyNC44IiB5MT0iMjQuNzEiIHkyPSIxNS41MyIgZ3JhZGllbnRVbml0cz0idXNlclNwYWNlT25Vc2UiPjxzdG9wIHN0b3AtY29sb3I9IiM0MjFGOEIiLz48c3RvcCBvZmZzZXQ9Ii41NSIgc3RvcC1jb2xvcj0iIzcyMzBGRiIvPjxzdG9wIG9mZnNldD0iMSIgc3RvcC1jb2xvcj0iIzk3NzNGRiIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjwvc3ZnPg==', webUrl: 'https://asigna.io', - chromeWebStoreUrl: - 'https://chromewebstore.google.com/detail/asigna-multisig/gopddoinbenlokghakiafackadkbnlid', + chromeWebStoreUrl: 'https://stx.asigna.io/', }, ];