Skip to content

Commit

Permalink
chore: Enable Fewcha (#5104)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xjojoex authored Nov 2, 2022
1 parent 0eaeea0 commit 40ea8c1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
5 changes: 5 additions & 0 deletions .changeset/heavy-tigers-live.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@pancakeswap/awgmi": patch
---

Integrate Fewcha wallet event
24 changes: 12 additions & 12 deletions apps/aptos/config/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ export const wallets: WalletConfigV2<ConnectorNames>[] = [
desktop: 'https://chrome.google.com/webstore/detail/pontem-aptos-wallet/phkbamefinggmakgklpkljjmgibohnba',
},
},
// {
// id: 'fewcha',
// title: 'Fewcha',
// icon: '/images/wallets/fewcha.png',
// get installed() {
// return typeof window !== 'undefined' && Boolean(window.fewcha)
// },
// connectorId: ConnectorNames.Fewcha,
// downloadLink: {
// desktop: 'https://fewcha.app/',
// },
// },
{
id: 'fewcha',
title: 'Fewcha',
icon: '/images/wallets/fewcha.png',
get installed() {
return typeof window !== 'undefined' && Boolean(window.fewcha)
},
connectorId: ConnectorNames.Fewcha,
downloadLink: {
desktop: 'https://fewcha.app/',
},
},
{
id: 'blocto',
title: 'Blocto',
Expand Down
45 changes: 26 additions & 19 deletions packages/awgmi/core/src/connectors/fewcha.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Types } from 'aptos'
import { Chain } from '../chain'
import { Connector, ConnectorTransactionResponse } from './base'
import { ConnectorNotFoundError } from '../errors'
import { Address } from '../types'
import { Connector, ConnectorTransactionResponse } from './base'
import { SignMessagePayload, SignMessageResponse } from './types'

declare global {
Expand All @@ -11,6 +10,9 @@ declare global {
}
}

type NetworkEvent = { name: string; network: string }
type AccountEvent = string

function methodWrapper(promiseFn: any) {
return async (...args: any) => {
const { data, status, method } = await promiseFn(...args)
Expand Down Expand Up @@ -40,12 +42,9 @@ export class FewchaConnector extends Connector {
try {
const provider = await this.getProvider()
if (!provider) throw new ConnectorNotFoundError()
if (provider.onAccountChange) {
provider.onAccountChange(this.onAccountsChanged)
}
if (provider.onNetworkChange) {
provider.onNetworkChange(this.onNetworkChanged)
}

window.addEventListener('aptos#changeNetwork', this.onNetworkChanged)
window.addEventListener('aptos#changeAccount', this.onAccountsChanged)

this.emit('message', { type: 'connecting' })

Expand All @@ -66,6 +65,8 @@ export class FewchaConnector extends Connector {
async disconnect() {
const provider = await this.getProvider()
if (!provider) return
window.removeEventListener('aptos#changeNetwork', this.onNetworkChanged)
window.removeEventListener('aptos#changeAccount', this.onAccountsChanged)
// eslint-disable-next-line consistent-return
return provider.disconnect()
}
Expand Down Expand Up @@ -118,19 +119,25 @@ export class FewchaConnector extends Connector {
return response
}

protected onAccountsChanged = async (address: Address) => {
if (!address) {
this.emit('disconnect')
} else {
this.emit('change', {
account: await this.account(),
})
protected onAccountsChanged = async (e: Event) => {
if (e instanceof CustomEvent) {
const address = (<CustomEvent<AccountEvent>>e).detail

if (!address) {
this.emit('disconnect')
} else {
this.emit('change', {
account: await this.account(),
})
}
}
}

protected onNetworkChanged = (network: string) => {
this.emit('change', {
network,
})
protected onNetworkChanged = (e: Event) => {
if (e instanceof CustomEvent) {
this.emit('change', {
network: (<CustomEvent<NetworkEvent>>e).detail.name,
})
}
}
}

1 comment on commit 40ea8c1

@vercel
Copy link

@vercel vercel bot commented on 40ea8c1 Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

aptos-web – ./apps/aptos

aptos-web.pancake.run
aptos.pancakeswap.finance
aptos.pancake.run
aptos-web-git-develop.pancake.run

Please sign in to comment.