diff --git a/src/anchor.ts b/src/anchor.ts index 9afd4b2..a2267d4 100644 --- a/src/anchor.ts +++ b/src/anchor.ts @@ -9,7 +9,6 @@ import { LoginContext, PrivateKey, PublicKey, - ResolvedSigningRequest, Serializer, SigningRequest, UInt64, diff --git a/src/index.ts b/src/index.ts index 69110b3..4f6653d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { Canceled, Checksum256, LoginContext, + Logo, PermissionLevel, PrivateKey, PromptResponse, @@ -80,10 +81,10 @@ export class WalletPluginAnchor extends AbstractWalletPlugin { readonly metadata: WalletPluginMetadata = WalletPluginMetadata.from({ name: 'Anchor', description: '', - logo: { + logo: Logo.from({ dark: 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPHN2ZyB3aWR0aD0iMTYwIiBoZWlnaHQ9IjE2MCIgdmlld0JveD0iMCAwIDI1NiAyNTYiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgPGcgdHJhbnNmb3JtPSJtYXRyaXgoMS40NCwgMCwgMCwgMS40NCwgLTguNTAxOTI1LCAtNTcuMDc0NTcpIiBzdHlsZT0iIj4KICAgIDx0aXRsZT5XaGl0ZTwvdGl0bGU+CiAgICA8Y2lyY2xlIGN4PSI5NC43OTMiIGN5PSIxMjguNTI0IiByPSI4MCIgZmlsbD0iI0ZCRkRGRiIvPgogICAgPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0gOTQuNzk5IDc4LjUyNCBDIDk3LjA5OCA3OC41MjQgOTkuMTk1IDc5LjgzNyAxMDAuMTk4IDgxLjkwNiBMIDEyNC4yMDQgMTMxLjQwNiBMIDEyNC43NDYgMTMyLjUyNCBMIDExMS40MDkgMTMyLjUyNCBMIDEwNy41MyAxMjQuNTI0IEwgODIuMDY5IDEyNC41MjQ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RkIiBkPSJNODAuMDA2MyAzMEM4Mi4zMDUxIDMwIDg0LjQwMTkgMzEuMzEzNCA4NS40MDUgMzMuMzgxOEwxMDkuNDExIDgyLjg4MjJMMTA5Ljk1MyA4NEg5Ni42MTYzTDkyLjczNjYgNzZINjcuMjc1OUw2My4zOTYxIDg0SDUwLjA1OTRMNTAuNjAxNyA4Mi44ODE4TDc0LjYwNzcgMzMuMzgxOEM3NS42MTA4IDMxLjMxMzQgNzcuNzA3NSAzMCA4MC4wMDYzIDMwWk03Mi4xMjU2IDY2SDg3Ljg4N0w4MC4wMDYzIDQ5Ljc1MDFMNzIuMTI1NiA2NlpNOTcuOTk5NSAxMDFIMTEwLjAwNUMxMDkuNjQ0IDExNy4xNTIgOTYuMjczOCAxMzAgODAuMDA2MyAxMzBDNjMuNzM4OCAxMzAgNTAuMzY4NiAxMTcuMTUyIDUwLjAwNzggMTAxSDYyLjAxMzFDNjIuMjk0MSAxMDguMzU0IDY3LjE4MDQgMTE0LjYzMSA3NC4wMDAzIDExNi45OTZWOTNDNzQuMDAwMyA4OS42ODYzIDc2LjY4NjYgODcgODAuMDAwMyA4N0M4My4zMTQgODcgODYuMDAwMyA4OS42ODYzIDg2LjAwMDMgOTNWMTE3QzkyLjgyNjUgMTE0LjYzOCA5Ny43MTgzIDEwOC4zNTkgOTcuOTk5NSAxMDFaIiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4K', - }, + }), homepage: 'https://greymass.com/anchor', download: 'https://greymass.com/anchor/download', }) @@ -199,10 +200,10 @@ export class WalletPluginAnchor extends AbstractWalletPlugin { resolved: ResolvedSigningRequest, context: TransactContext ): Promise { - return this.handleSignatureRequest(resolved, context) + return this.handleSigningRequest(resolved, context) } - private async handleSignatureRequest( + private async handleSigningRequest( resolved: ResolvedSigningRequest, context: TransactContext ): Promise { @@ -224,6 +225,32 @@ export class WalletPluginAnchor extends AbstractWalletPlugin { // Add the callback to the request const callback = setTransactionCallback(modifiedRequest, this.buoyUrl) + const request = modifiedRequest.encode(true, false) + + const signManually = () => { + context.ui?.prompt({ + title: t('transact.sign_manually.title', {default: 'Sign manually'}), + body: t('transact.sign_manually.body', { + default: + 'Scan the QR-code with Anchor on another device or use the button to open it here.', + }), + elements: [ + { + type: 'qr', + data: String(request), + }, + { + type: 'link', + label: t('transact.sign_manually.link.title', {default: 'Open Anchor'}), + data: { + href: String(request), + label: t('transact.sign_manually.link.title', {default: 'Open Anchor'}), + }, + }, + ], + }) + } + // Tell Wharf we need to prompt the user with a QR code and a button const promptPromise: Cancelable = context.ui.prompt({ title: t('transact.title', {default: 'Complete using Anchor'}), @@ -240,10 +267,11 @@ export class WalletPluginAnchor extends AbstractWalletPlugin { }, }, { - type: 'link', + type: 'button', label: t('transact.label', {default: 'Sign manually or with another device'}), data: { href: modifiedRequest.encode(true, false, 'esr:'), + onClick: signManually, label: t('transact.label', { default: 'Sign manually or with another device', }), diff --git a/test/tests/anchor.ts b/test/tests/anchor.ts index 78a22dd..370dccb 100644 --- a/test/tests/anchor.ts +++ b/test/tests/anchor.ts @@ -36,7 +36,7 @@ suite('anchor', () => { test('sets the callback on the request and returns the callback data', async () => { const resolved = await makeMockResolvedSigningRequest() const buoyUrl = 'https://example.com/buoy' - const {service, channel} = setTransactionCallback(resolved, buoyUrl) + const {service, channel} = setTransactionCallback(resolved.request, buoyUrl) const resolvedCallback = resolved.getCallback([mockSignature1])