Skip to content

Commit

Permalink
enhancement: displaying link to metamask page when snap is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
dafuga committed Aug 22, 2024
1 parent ad08463 commit 71ebdbc
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@wharfkit/account-creation-plugin-metamask",
"description": "A MetaMask plugin to create EOS accounts using Metamask public keys.",
"version": "1.0.0-RC3",
"version": "1.0.0-rc4",
"homepage": "https://github.com/wharfkit/wallet-plugin-metamask",
"license": "BSD-3-Clause",
"main": "lib/account-creation-plugin-metamask.js",
Expand Down
37 changes: 32 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export type GetSnapsResponse = Record<string, Snap>
const DEFAULT_SNAP_ORIGIN = 'local:http://localhost:8080'
const ACCOUNT_CREATION_SERVICE_URL =
'https://adding-login-through-apple.account-creation-portal.pages.dev/buy'
const defaultSetupPageUrl = 'https://unicove.com/eos/metamask'

export interface AccountCreationPluginMetaMaskConfig {
setupPageUrl?: string
}

export class AccountCreationPluginMetamask
extends AbstractAccountCreationPlugin
Expand All @@ -25,6 +30,7 @@ export class AccountCreationPluginMetamask
public installedSnap: Snap | null = null
public provider: MetaMaskInpageProvider | null = null
public isFlask = false
public setupPageUrl

readonly config: AccountCreationPluginConfig = {
requiresChainSelect: true,
Expand All @@ -36,6 +42,12 @@ export class AccountCreationPluginMetamask
description: 'Plugin to create EOS accounts using Metamask public key.',
})

constructor(walletPluginMetaMaskConfig?: AccountCreationPluginMetaMaskConfig) {
super()

this.setupPageUrl = walletPluginMetaMaskConfig?.setupPageUrl || defaultSetupPageUrl
}

get id(): string {
return 'account-creation-plugin-metamask'
}
Expand Down Expand Up @@ -85,18 +97,33 @@ export class AccountCreationPluginMetamask
}
}

async initialize() {
async initialize(context?: CreateAccountContext) {
if (!this.provider) {
this.provider = await getSnapsProvider()
}
if (this.provider && !this.installedSnap) {
this.isFlask = await checkIsFlask(this.provider)
await this.setSnap()
if (!this.installedSnap) {
await this.requestSnap()
if (this.installedSnap) {
await this.initialize()
}
context?.ui?.prompt({
title: 'Antelope Snap Setup Required',
body: `
It looks like the Antelope snap for MetaMask isn't installed yet.
Click the button below to go to our setup page:
`,
elements: [
{
type: 'button',
label: 'Go to Setup Page',
data: {
onClick: () => {
window.open(this.setupPageUrl, '_blank')
},
},
},
],
})
}
}
}
Expand Down

0 comments on commit 71ebdbc

Please sign in to comment.