-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: migrate coin98 to use Hub #992
Open
mikasackermn
wants to merge
3
commits into
next
Choose a base branch
from
feat/rf-1861-migrate-coin98-to-use-Hub
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,22 @@ | ||
import { type ProviderInfo } from '@rango-dev/wallets-core'; | ||
|
||
export const WALLET_ID = 'coin98'; | ||
|
||
export const info: ProviderInfo = { | ||
name: 'Coin98', | ||
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/coin98/icon.svg', | ||
extensions: { | ||
chrome: | ||
'https://chrome.google.com/webstore/detail/coin98-wallet/aeachknmefphepccionboohckonoeemg', | ||
brave: | ||
'https://chrome.google.com/webstore/detail/coin98-wallet/aeachknmefphepccionboohckonoeemg', | ||
homepage: 'https://coin98.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
File renamed without changes.
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,12 @@ | ||
import { defineVersions } from '@rango-dev/wallets-core/utils'; | ||
|
||
import { buildLegacyProvider } from './legacy/index.js'; | ||
import { buildProvider } from './provider.js'; | ||
|
||
const versions = () => | ||
defineVersions() | ||
.version('0.0.0', buildLegacyProvider()) | ||
.version('1.0.0', buildProvider()) | ||
.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,36 @@ | ||
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 { evmCoin98 } from '../utils.js'; | ||
|
||
const [changeAccountSubscriber, changeAccountCleanup] = | ||
actions.changeAccountSubscriber(evmCoin98); | ||
|
||
/* | ||
* TODO: If user imported a private key for EVM, it hasn't solana. | ||
* when trying to connect to solana for this user we go through `-32603` which is an internal error. | ||
* If phantom added an specific error code for this situation, we can consider handling the error here. | ||
* @see https://docs.phantom.app/solana/errors | ||
*/ | ||
const connect = builders | ||
.connect() | ||
.action(actions.connect(evmCoin98)) | ||
.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,64 @@ | ||
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 { WALLET_ID } from '../constants.js'; | ||
import { getSolanaAccounts, solanaCoin98 } from '../utils.js'; | ||
|
||
const [changeAccountSubscriber, changeAccountCleanup] = | ||
actions.changeAccountSubscriber(solanaCoin98); | ||
|
||
/* | ||
* TODO: If user imported a private key for EVM, it hasn't solana. | ||
* when trying to connect to solana for this user we go through `-32603` which is an internal error. | ||
* If phantom added an specific error code for this situation, we can consider handling the error here. | ||
* @see https://docs.phantom.app/solana/errors | ||
*/ | ||
const connect = builders | ||
.connect() | ||
.action(async function () { | ||
const solanaInstance = solanaCoin98(); | ||
const result = await getSolanaAccounts(solanaInstance); | ||
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,23 @@ | ||
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 { coin98 as coin98Instances } from './utils.js'; | ||
|
||
const buildProvider = () => | ||
new ProviderBuilder(WALLET_ID) | ||
.init(function (context) { | ||
const [, setState] = context.state(); | ||
|
||
if (coin98Instances()) { | ||
setState('installed', true); | ||
console.debug('[phantom] instance detected.', context); | ||
} | ||
}) | ||
.config('info', info) | ||
.add('solana', solana) | ||
.add('evm', evm) | ||
.build(); | ||
|
||
export { buildProvider }; |
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 { LegacyNetworks } from '@rango-dev/wallets-core/legacy'; | ||
import { | ||
Networks, | ||
type ProviderConnectResult, | ||
} from '@rango-dev/wallets-shared'; | ||
|
||
export function coin98() { | ||
const { coin98, ethereum } = window; | ||
|
||
if (!coin98) { | ||
return null; | ||
} | ||
|
||
const instances = new Map(); | ||
|
||
// When disabled overring metamask | ||
if (coin98.provider) { | ||
instances.set(Networks.ETHEREUM, coin98.provider); | ||
} | ||
if (ethereum && ethereum.isCoin98) { | ||
instances.set(Networks.ETHEREUM, ethereum); | ||
} | ||
if (coin98.sol) { | ||
instances.set(Networks.SOLANA, coin98.sol); | ||
} | ||
|
||
return instances; | ||
} | ||
|
||
/* | ||
*This is how coin98 is getting solana accounts. | ||
*That's the reason we haven't moved it to `shared` | ||
*/ | ||
export async function getSolanaAccounts( | ||
instance: any | ||
): Promise<ProviderConnectResult> { | ||
await instance.enable(); | ||
const accounts = await instance.request({ method: 'sol_accounts' }); | ||
return { | ||
accounts, | ||
chainId: LegacyNetworks.SOLANA, | ||
}; | ||
} | ||
|
||
export function solanaCoin98(): SolanaProviderApi { | ||
const instance = coin98(); | ||
const solanaInstance = instance?.get(LegacyNetworks.SOLANA); | ||
|
||
if (!solanaInstance) { | ||
throw new Error( | ||
'Coin98 not injected or Solana not enabled. Please check your wallet.' | ||
); | ||
} | ||
|
||
return solanaInstance; | ||
} | ||
|
||
export function evmCoin98(): EvmProviderApi { | ||
const instances = coin98(); | ||
|
||
const evmInstance = instances?.get(LegacyNetworks.ETHEREUM); | ||
|
||
if (!evmInstance) { | ||
throw new Error( | ||
'Coin98 not injected or EVM not enabled. Please check your wallet.' | ||
); | ||
} | ||
|
||
return evmInstance as EvmProviderApi; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you didn't specify the return type for
getSolanaAccounts
inutitls
. this has an implicit any type. Please fix it in there or at least declareaccount
asany
explicitly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed