Skip to content

Commit

Permalink
Merge pull request #99 from OneKeyHQ/fix/cardano-inject
Browse files Browse the repository at this point in the history
fix: cardano dapp inject
  • Loading branch information
originalix authored Jan 30, 2023
2 parents 1789454 + 976f570 commit 5476950
Show file tree
Hide file tree
Showing 29 changed files with 188 additions and 121 deletions.
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-core",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -29,9 +29,9 @@
"build-version-info": "node ./scripts/buildVersionInfo.js"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-events": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/cross-inpage-provider-errors": "1.1.19",
"@onekeyfe/cross-inpage-provider-events": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19",
"events": "^3.3.0",
"lodash": "^4.17.21",
"ms": "^2.1.3"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/versionInfo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const version = '1.1.17';
const version = '1.1.18';
const versionBuild = '2020-0101-1';

export default {
Expand Down
6 changes: 3 additions & 3 deletions packages/desktop/desktop-bridge-injected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/desktop-bridge-injected",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -34,7 +34,7 @@
"electron": "^17.2.0"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18"
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19"
}
}
2 changes: 1 addition & 1 deletion packages/empty/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-empty",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/errors/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-errors",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down
2 changes: 1 addition & 1 deletion packages/events/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-events",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down
22 changes: 11 additions & 11 deletions packages/example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-example",
"version": "1.1.18",
"version": "1.1.19",
"private": true,
"scripts": {
"postinstall": "patch-package",
Expand All @@ -17,16 +17,16 @@
"@metamask/onboarding": "^1.0.1",
"@mysten/wallet-adapter-all-wallets": "^0.3.3",
"@mysten/wallet-adapter-react": "^8.0.1",
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/onekey-aptos-provider": "1.1.18",
"@onekeyfe/onekey-cardano-provider": "1.1.18",
"@onekeyfe/onekey-conflux-provider": "1.1.18",
"@onekeyfe/onekey-cosmos-provider": "1.1.18",
"@onekeyfe/onekey-near-provider": "1.1.18",
"@onekeyfe/onekey-solana-provider": "1.1.18",
"@onekeyfe/onekey-sui-provider": "1.1.18",
"@onekeyfe/onekey-tron-provider": "1.1.18",
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19",
"@onekeyfe/onekey-aptos-provider": "1.1.19",
"@onekeyfe/onekey-cardano-provider": "1.1.19",
"@onekeyfe/onekey-conflux-provider": "1.1.19",
"@onekeyfe/onekey-cosmos-provider": "1.1.19",
"@onekeyfe/onekey-near-provider": "1.1.19",
"@onekeyfe/onekey-solana-provider": "1.1.19",
"@onekeyfe/onekey-sui-provider": "1.1.19",
"@onekeyfe/onekey-tron-provider": "1.1.19",
"@solana/web3.js": "^1.41.3",
"@starcoin/starcoin": "^2.1.6",
"@starcoin/starmask-onboarding": "^1.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/extension/extension-bridge-hosted/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/extension-bridge-hosted",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,7 +28,7 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18"
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19"
}
}
6 changes: 3 additions & 3 deletions packages/extension/extension-bridge-injected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/extension-bridge-injected",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,7 +28,7 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18"
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19"
}
}
14 changes: 7 additions & 7 deletions packages/injected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/cross-inpage-provider-injected",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -42,12 +42,12 @@
"electron": "*"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/desktop-bridge-injected": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18",
"@onekeyfe/inpage-providers-hub": "1.1.18",
"@onekeyfe/native-bridge-injected": "1.1.18",
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19",
"@onekeyfe/desktop-bridge-injected": "1.1.19",
"@onekeyfe/extension-bridge-injected": "1.1.19",
"@onekeyfe/inpage-providers-hub": "1.1.19",
"@onekeyfe/native-bridge-injected": "1.1.19",
"buffer": "^6.0.3"
}
}
6 changes: 3 additions & 3 deletions packages/native/native-bridge-injected/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/native-bridge-injected",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,7 +28,7 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18"
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19"
}
}
26 changes: 13 additions & 13 deletions packages/providers/inpage-providers-hub/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/inpage-providers-hub",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,18 +28,18 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/onekey-aptos-provider": "1.1.18",
"@onekeyfe/onekey-cardano-provider": "1.1.18",
"@onekeyfe/onekey-conflux-provider": "1.1.18",
"@onekeyfe/onekey-cosmos-provider": "1.1.18",
"@onekeyfe/onekey-eth-provider": "1.1.18",
"@onekeyfe/onekey-private-provider": "1.1.18",
"@onekeyfe/onekey-solana-provider": "1.1.18",
"@onekeyfe/onekey-starcoin-provider": "1.1.18",
"@onekeyfe/onekey-sui-provider": "1.1.18",
"@onekeyfe/onekey-tron-provider": "1.1.18",
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19",
"@onekeyfe/onekey-aptos-provider": "1.1.19",
"@onekeyfe/onekey-cardano-provider": "1.1.19",
"@onekeyfe/onekey-conflux-provider": "1.1.19",
"@onekeyfe/onekey-cosmos-provider": "1.1.19",
"@onekeyfe/onekey-eth-provider": "1.1.19",
"@onekeyfe/onekey-private-provider": "1.1.19",
"@onekeyfe/onekey-solana-provider": "1.1.19",
"@onekeyfe/onekey-starcoin-provider": "1.1.19",
"@onekeyfe/onekey-sui-provider": "1.1.19",
"@onekeyfe/onekey-tron-provider": "1.1.19",
"web3": "^1.7.3"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ProviderStarcoin } from '@onekeyfe/onekey-starcoin-provider';
import { ProviderAptos, ProviderAptosMartian } from '@onekeyfe/onekey-aptos-provider';
import { ProviderConflux } from '@onekeyfe/onekey-conflux-provider';
import { ProviderTron } from '@onekeyfe/onekey-tron-provider';
import { ProviderCardano } from '@onekeyfe/onekey-cardano-provider';
import { ProviderCardano, defineWindowCardanoProperty } from '@onekeyfe/onekey-cardano-provider';
import { ProviderCosmos } from '@onekeyfe/onekey-cosmos-provider';
import { consts } from '@onekeyfe/cross-inpage-provider-core';
import { ProviderSui, registerSuiWallet } from '@onekeyfe/onekey-sui-provider';
Expand Down Expand Up @@ -193,7 +193,8 @@ function injectWeb3Provider(): unknown {
defineWindowProperty('conflux', conflux);
defineWindowProperty('tronLink', tron);
defineWindowProperty('suiWallet', sui);
defineWindowProperty('cardano', cardano);

defineWindowCardanoProperty('cardano', cardano)

// cosmos keplr
defineWindowProperty('keplr', cosmos);
Expand Down
10 changes: 5 additions & 5 deletions packages/providers/onekey-aptos-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/onekey-aptos-provider",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider"
],
Expand Down Expand Up @@ -28,10 +28,10 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18",
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-errors": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19",
"@onekeyfe/extension-bridge-injected": "1.1.19",
"aptos": "^1.3.17",
"eth-rpc-errors": "^4.0.3"
}
Expand Down
12 changes: 6 additions & 6 deletions packages/providers/onekey-cardano-provider/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onekeyfe/onekey-cardano-provider",
"version": "1.1.18",
"version": "1.1.19",
"keywords": [
"cross-inpage-provider",
"cardano"
Expand Down Expand Up @@ -29,10 +29,10 @@
"start": "tsc --watch"
},
"dependencies": {
"@onekeyfe/cross-inpage-provider-core": "1.1.18",
"@onekeyfe/cross-inpage-provider-errors": "1.1.18",
"@onekeyfe/cross-inpage-provider-types": "1.1.18",
"@onekeyfe/extension-bridge-injected": "1.1.18",
"@onekeyfe/onekey-cardano-provider": "1.1.18"
"@onekeyfe/cross-inpage-provider-core": "1.1.19",
"@onekeyfe/cross-inpage-provider-errors": "1.1.19",
"@onekeyfe/cross-inpage-provider-types": "1.1.19",
"@onekeyfe/extension-bridge-injected": "1.1.19",
"@onekeyfe/onekey-cardano-provider": "1.1.19"
}
}
51 changes: 43 additions & 8 deletions packages/providers/onekey-cardano-provider/src/ProviderCardano.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */

import { ProviderBase } from '@onekeyfe/cross-inpage-provider-core'
import { ProviderCardanoBase } from './ProviderCardanoBase'
import { IInpageProviderConfig } from '@onekeyfe/cross-inpage-provider-core';
Expand All @@ -8,6 +11,8 @@ import { Cbor, Bytes, Cip30DataSignature, Cip30Wallet, NetworkId, Paginate, Wall
import * as TypeUtils from './type-utils'


export const NAMI_TARGET = 'nami-wallet';

export type CardanoRequest = WalletApi & {
connect: () => Promise<{ account: string }>
// override the type of the request method
Expand Down Expand Up @@ -63,13 +68,10 @@ class ProviderCardano extends ProviderCardanoBase implements IProviderCardano {
return this._account !== null
}

get onekey() {
return this.walletInfo()
}
onekey: Cip30Wallet

nami: Cip30Wallet

get nami() {
return this.walletInfo()
}

constructor(props: OneKeyCardanoProviderProps) {
super({
Expand All @@ -78,6 +80,14 @@ class ProviderCardano extends ProviderCardanoBase implements IProviderCardano {
});

this._registerEvents();

this.nami = {
...this.walletInfo(),
name: 'Nami',
}
this.onekey = {
...this.walletInfo()
}
}

private _registerEvents() {
Expand All @@ -91,7 +101,6 @@ class ProviderCardano extends ProviderCardanoBase implements IProviderCardano {
this._handleAccountChange(params as CardanoAccount);
}
});

}

private _callBridge<T extends keyof JsBridgeRequest>(params: {
Expand Down Expand Up @@ -183,7 +192,13 @@ class ProviderCardano extends ProviderCardanoBase implements IProviderCardano {

signData: (addr: Cbor, payload: Bytes) => this.signData(addr, payload),

submitTx: (tx: Cbor) => this.submitTx(tx)
submitTx: (tx: Cbor) => this.submitTx(tx),

experimental: {
on: (eventName: string, callback: (detail: any) => void) => this.namiOn(eventName, callback),
off: () => this.namiOff(),
getCollateral: () => this.getCollateral(),
},
}

if (!this.account) {
Expand Down Expand Up @@ -281,6 +296,26 @@ class ProviderCardano extends ProviderCardanoBase implements IProviderCardano {
params: tx
})
}

/**
* @param {string} eventName
* @param {Function} callback
*/
namiOn(eventName: string, callback: (detail: any) => void) {
const handler = (event: any) => callback(event.detail);

// @ts-ignore
const events = window.cardano.nami._events[eventName] || [];

// @ts-ignore
window.cardano.nami._events[eventName] = [...events, [callback, handler]];

window.addEventListener(`${NAMI_TARGET}${eventName}`, handler);
}

namiOff() {
// empty
}
}

export {ProviderCardano}
1 change: 1 addition & 0 deletions packages/providers/onekey-cardano-provider/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './ProviderCardano'
export * from './ProviderCardanoBase'
export * from './inject'
Loading

0 comments on commit 5476950

Please sign in to comment.