-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f59449
commit 3151b35
Showing
12 changed files
with
255 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { type ProviderInfo } from '@rango-dev/wallets-core'; | ||
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy'; | ||
|
||
export const EVM_SUPPORTED_CHAINS = [ | ||
LegacyNetworks.ETHEREUM, | ||
LegacyNetworks.POLYGON, | ||
]; | ||
|
||
export const WALLET_ID = 'coinbase'; | ||
|
||
export const info: ProviderInfo = { | ||
name: 'Coinbase', | ||
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/coinbase/icon.svg', | ||
extensions: { | ||
chrome: | ||
'https://chrome.google.com/webstore/detail/coinbase-wallet-extension/hnfanknocfeofbddgcijnmhnfnkdnaad', | ||
brave: | ||
'https://chrome.google.com/webstore/detail/coinbase-wallet-extension/hnfanknocfeofbddgcijnmhnfnkdnaad', | ||
homepage: 'https://www.coinbase.com/wallet', | ||
}, | ||
properties: [ | ||
{ | ||
name: 'detached', | ||
// if you are adding a new namespace, don't forget to also update `getWalletInfo` | ||
value: ['evm', 'solana'], | ||
}, | ||
], | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
wallets/provider-coinbase/src/signer.ts → ...ts/provider-coinbase/src/legacy/signer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineVersions } from '@rango-dev/wallets-core/utils'; | ||
|
||
import { legacyProvider } from './legacy/index.js'; | ||
import { provider } from './provider.js'; | ||
|
||
const versions = defineVersions() | ||
.version('0.0.0', legacyProvider) | ||
.version('1.0.0', provider) | ||
.build(); | ||
|
||
export { versions }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { EvmActions } from '@rango-dev/wallets-core/namespaces/evm'; | ||
|
||
import { NamespaceBuilder } from '@rango-dev/wallets-core'; | ||
import { builders as commonBuilders } from '@rango-dev/wallets-core/namespaces/common'; | ||
import { actions, builders } from '@rango-dev/wallets-core/namespaces/evm'; | ||
|
||
import { WALLET_ID } from '../constants.js'; | ||
import { evmCoinbase } from '../utils.js'; | ||
|
||
const [changeAccountSubscriber, changeAccountCleanup] = | ||
actions.changeAccountSubscriber(evmCoinbase); | ||
|
||
const connect = builders | ||
.connect() | ||
.action(actions.connect(evmCoinbase)) | ||
.before(changeAccountSubscriber) | ||
.or(changeAccountCleanup) | ||
.build(); | ||
|
||
const disconnect = commonBuilders | ||
.disconnect<EvmActions>() | ||
.after(changeAccountCleanup) | ||
.build(); | ||
|
||
const evm = new NamespaceBuilder<EvmActions>('EVM', WALLET_ID) | ||
.action(connect) | ||
.action(disconnect) | ||
.build(); | ||
|
||
export { evm }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import type { CaipAccount } from '@rango-dev/wallets-core/namespaces/common'; | ||
import type { SolanaActions } from '@rango-dev/wallets-core/namespaces/solana'; | ||
|
||
import { NamespaceBuilder } from '@rango-dev/wallets-core'; | ||
import { builders as commonBuilders } from '@rango-dev/wallets-core/namespaces/common'; | ||
import { | ||
actions, | ||
builders, | ||
CAIP_NAMESPACE, | ||
CAIP_SOLANA_CHAIN_ID, | ||
} from '@rango-dev/wallets-core/namespaces/solana'; | ||
import { CAIP } from '@rango-dev/wallets-core/utils'; | ||
import { getSolanaAccounts } from '@rango-dev/wallets-shared'; | ||
|
||
import { WALLET_ID } from '../constants.js'; | ||
import { solanaCoinbase } from '../utils.js'; | ||
|
||
const [changeAccountSubscriber, changeAccountCleanup] = | ||
actions.changeAccountSubscriber(solanaCoinbase); | ||
|
||
const connect = builders | ||
.connect() | ||
.action(async function () { | ||
const solanaInstance = solanaCoinbase(); | ||
const result = await getSolanaAccounts({ | ||
instance: solanaInstance, | ||
meta: [], | ||
}); | ||
if (Array.isArray(result)) { | ||
throw new Error( | ||
'Expecting solana response to be a single value, not an array.' | ||
); | ||
} | ||
|
||
const formatAccounts = result.accounts.map( | ||
(account) => | ||
CAIP.AccountId.format({ | ||
address: account, | ||
chainId: { | ||
namespace: CAIP_NAMESPACE, | ||
reference: CAIP_SOLANA_CHAIN_ID, | ||
}, | ||
}) as CaipAccount | ||
); | ||
|
||
return formatAccounts; | ||
}) | ||
.before(changeAccountSubscriber) | ||
.or(changeAccountCleanup) | ||
.build(); | ||
|
||
const disconnect = commonBuilders | ||
.disconnect<SolanaActions>() | ||
.after(changeAccountCleanup) | ||
.build(); | ||
|
||
const solana = new NamespaceBuilder<SolanaActions>('Solana', WALLET_ID) | ||
.action(connect) | ||
.action(disconnect) | ||
.build(); | ||
|
||
export { solana }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ProviderBuilder } from '@rango-dev/wallets-core'; | ||
|
||
import { info, WALLET_ID } from './constants.js'; | ||
import { evm } from './namespaces/evm.js'; | ||
import { solana } from './namespaces/solana.js'; | ||
import { coinbase as coinbaseInstance } from './utils.js'; | ||
|
||
const provider = new ProviderBuilder(WALLET_ID) | ||
.init(function (context) { | ||
const [, setState] = context.state(); | ||
|
||
if (coinbaseInstance()) { | ||
setState('installed', true); | ||
console.debug('[coinbase] instance detected.', context); | ||
} | ||
}) | ||
.config('info', info) | ||
.add('solana', solana) | ||
.add('evm', evm) | ||
.build(); | ||
|
||
export { provider }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import type { ProviderAPI as EvmProviderApi } from '@rango-dev/wallets-core/namespaces/evm'; | ||
import type { ProviderAPI as SolanaProviderApi } from '@rango-dev/wallets-core/namespaces/solana'; | ||
import type { ProviderConnectResult } from '@rango-dev/wallets-shared'; | ||
|
||
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy'; | ||
|
||
type Provider = Map<string, unknown>; | ||
|
||
export function coinbase(): Provider | null { | ||
const { coinbaseWalletExtension, coinbaseSolana } = window; | ||
|
||
if (!coinbaseSolana && !coinbaseWalletExtension) { | ||
return null; | ||
} | ||
|
||
const instances = new Map(); | ||
|
||
if (coinbaseWalletExtension) { | ||
instances.set(LegacyNetworks.ETHEREUM, coinbaseWalletExtension); | ||
} | ||
|
||
if (coinbaseSolana) { | ||
instances.set(LegacyNetworks.SOLANA, coinbaseSolana); | ||
} | ||
|
||
return instances; | ||
} | ||
|
||
export function evmCoinbase(): EvmProviderApi { | ||
const instances = coinbase(); | ||
|
||
const evmInstance = instances?.get(LegacyNetworks.ETHEREUM); | ||
|
||
if (!evmInstance) { | ||
throw new Error( | ||
'Coinbase not injected or EVM not enabled. Please check your wallet.' | ||
); | ||
} | ||
|
||
return evmInstance as EvmProviderApi; | ||
} | ||
|
||
export function solanaCoinbase(): SolanaProviderApi { | ||
const instance = coinbase(); | ||
const solanaInstance = instance?.get(LegacyNetworks.SOLANA); | ||
|
||
if (!solanaInstance) { | ||
throw new Error( | ||
'Coinbase not injected or Solana not enabled. Please check your wallet.' | ||
); | ||
} | ||
|
||
return solanaInstance; | ||
} | ||
|
||
export async function getSolanaAccounts( | ||
instance: any | ||
): Promise<ProviderConnectResult[]> { | ||
const solanaInstance = await instance.get(LegacyNetworks.SOLANA); | ||
const results: ProviderConnectResult[] = []; | ||
|
||
if (solanaInstance) { | ||
await solanaInstance.connect(); | ||
const account = solanaInstance.publicKey.toString(); | ||
|
||
results.push({ | ||
accounts: account ? [account] : [], | ||
chainId: LegacyNetworks.SOLANA, | ||
}); | ||
} | ||
|
||
return results; | ||
} |