Skip to content

Commit

Permalink
Merge pull request #37 from wharfkit/dafuga-fixes
Browse files Browse the repository at this point in the history
dafuga fixes
  • Loading branch information
aaroncox authored Sep 19, 2023
2 parents 18e06d0 + cfbad18 commit 10eccf9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
LoginContext,
PrivateKey,
PublicKey,
ResolvedSigningRequest,
Serializer,
SigningRequest,
UInt64,
Expand Down
38 changes: 33 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Canceled,
Checksum256,
LoginContext,
Logo,
PermissionLevel,
PrivateKey,
PromptResponse,
Expand Down Expand Up @@ -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+CiAgICA8Y2lyY2xlIGN4PSI5NC43OTMiIGN5PSIxMjguNTI0IiByPSI4MCIgZmlsbD0iI0ZCRkRGRiIvPgogICAgPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik0gOTQuNzk5IDc4LjUyNCBDIDk3LjA5OCA3OC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odHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxjaXJjbGUgY3g9IjgwIiBjeT0iODAiIHI9IjgwIiBmaWxsPSIjMzY1MEEyIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNODAuMDA2MyAzMEM4Mi4zMDUxIDMwIDg0LjQwMTkgMzEuMzEzNCA4NS40MDUgMzMuMzgxOEwxMDkuNDExIDgyLjg4MjJMMTA5Ljk1MyA4NEg5Ni42MTYzTDkyLjczNjYgNzZINjcuMjc1OUw2My4zOTYxIDg0SDUwLjA1OTRMNTAuNjAxNyA4Mi44ODE4TDc0LjYwNzcgMzMuMzgxOEM3NS42MTA4IDMxLjMxMzQgNzcuNzA3NSAzMCA4MC4wMDYzIDMwWk03Mi4xMjU2IDY2SDg3Ljg4N0w4MC4wMDYzIDQ5Ljc1MDFMNzIuMTI1NiA2NlpNOTcuOTk5NSAxMDFIMTEwLjAwNUMxMDkuNjQ0IDExNy4xNTIgOTYuMjczOCAxMzAgODAuMDA2MyAxMzBDNjMuNzM4OCAxMzAgNTAuMzY4NiAxMTcuMTUyIDUwLjAwNzggMTAxSDYyLjAxMzFDNjIuMjk0MSAxMDguMzU0IDY3LjE4MDQgMTE0LjYzMSA3NC4wMDAzIDExNi45OTZWOTNDNzQuMDAwMyA4OS42ODYzIDc2LjY4NjYgODcgODAuMDAwMyA4N0M4My4zMTQgODcgODYuMDAwMyA4OS42ODYzIDg2LjAwMDMgOTNWMTE3QzkyLjgyNjUgMTE0LjYzOCA5Ny43MTgzIDEwOC4zNTkgOTcuOTk5NSAxMDFaIiBmaWxsPSJ3aGl0ZSIvPgo8L3N2Zz4K',
},
}),
homepage: 'https://greymass.com/anchor',
download: 'https://greymass.com/anchor/download',
})
Expand Down Expand Up @@ -199,10 +200,10 @@ export class WalletPluginAnchor extends AbstractWalletPlugin {
resolved: ResolvedSigningRequest,
context: TransactContext
): Promise<WalletPluginSignResponse> {
return this.handleSignatureRequest(resolved, context)
return this.handleSigningRequest(resolved, context)
}

private async handleSignatureRequest(
private async handleSigningRequest(
resolved: ResolvedSigningRequest,
context: TransactContext
): Promise<WalletPluginSignResponse> {
Expand All @@ -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<PromptResponse> = context.ui.prompt({
title: t('transact.title', {default: 'Complete using Anchor'}),
Expand All @@ -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',
}),
Expand Down
2 changes: 1 addition & 1 deletion test/tests/anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit 10eccf9

Please sign in to comment.