Skip to content

wip: integrating gemwallet #1096

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

Draft
wants to merge 1 commit into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions wallets/provider-all/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as defaultInjected from '@rango-dev/provider-default';
import * as enkrypt from '@rango-dev/provider-enkrypt';
import * as exodus from '@rango-dev/provider-exodus';
import * as frontier from '@rango-dev/provider-frontier';
import { versions as gemwallet } from '@rango-dev/provider-gemwallet';
import * as halo from '@rango-dev/provider-halo';
import * as keplr from '@rango-dev/provider-keplr';
import * as leapCosmos from '@rango-dev/provider-leap-cosmos';
Expand Down Expand Up @@ -142,5 +143,6 @@ export const allProviders = (
lazyProvider(legacyProviderImportsToVersionsInterface(trezor)),
lazyProvider(legacyProviderImportsToVersionsInterface(solflare)),
lazyProvider(legacyProviderImportsToVersionsInterface(mytonwallet)),
gemwallet,
];
};
33 changes: 33 additions & 0 deletions wallets/provider-gemwallet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@rango-dev/provider-gemwallet",
"version": "0.1.0",
"license": "MIT",
"type": "module",
"source": "./src/mod.ts",
"main": "./dist/mod.js",
"exports": {
".": "./dist/mod.js"
},
"typings": "dist/mod.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"build": "node ../../scripts/build/command.mjs --path wallets/provider-gemwallet --inputs src/mod.ts",
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
"clean": "rimraf dist",
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
"lint": "eslint \"**/*.{ts,tsx}\""
},
"dependencies": {
"@rango-dev/signer-solana": "^0.38.1-next.0",
"@rango-dev/wallets-shared": "^0.43.1-next.2",
"@gemwallet/api": "^3.8.0",
"xrpl": "^4.2.0",
"rango-types": "^0.1.82"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions wallets/provider-gemwallet/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# @rango-dev/provider-gemwallet
20 changes: 20 additions & 0 deletions wallets/provider-gemwallet/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { type ProviderInfo } from '@rango-dev/wallets-core';

export const WALLET_ID = 'gemwallet';

export const info: ProviderInfo = {
name: 'GemWallet',
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/phantom/icon.svg',
extensions: {
chrome:
'https://chromewebstore.google.com/detail/gemwallet/egebedonbdapoieedfcfkofloclfghab',
homepage: 'https://gemwallet.app/',
},
properties: [
{
name: 'detached',
// if you are adding a new namespace, don't forget to also update `getWalletInfo`
value: ['Solana'],
},
],
};
51 changes: 51 additions & 0 deletions wallets/provider-gemwallet/src/legacy/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';

import { chains as solanaChains } from '@rango-dev/wallets-core/namespaces/solana';
import {
type BlockchainMeta,
DefaultSignerFactory,
solanaBlockchain,
} from 'rango-types';

import { WALLET_ID } from '../constants.js';

export const buildLegacyProvider: () => LegacyProviderInterface = () => ({
config: {
type: WALLET_ID,
},
getWalletInfo: (allBlockChains) => {
const supportedChains: BlockchainMeta[] = solanaBlockchain(allBlockChains);

return {
name: 'GemWallet',
img: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/phantom/icon.svg',
installLink: {
CHROME:
'https://chrome.google.com/webstore/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa',

DEFAULT: 'https://phantom.app/',
},
color: '#4d40c6',
// if you are adding a new namespace, don't forget to also update `properties`
needsNamespace: {
selection: 'multiple',
data: [
{
label: 'Solana',
value: 'Solana',
id: 'SOLANA',
chains: [solanaChains.solana],
},
],
},
supportedChains,
};
},
connect: async () => {
return [];
},
getInstance: () => ({}),
getSigners: async () => {
return new DefaultSignerFactory();
},
});
12 changes: 12 additions & 0 deletions wallets/provider-gemwallet/src/mod.ts
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 };
37 changes: 37 additions & 0 deletions wallets/provider-gemwallet/src/namespaces/solana.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { CaipAccount } from '@rango-dev/wallets-core/namespaces/common';
import type { SolanaActions } from '@rango-dev/wallets-core/namespaces/solana';

import { getAddress } from '@gemwallet/api';
import { NamespaceBuilder } from '@rango-dev/wallets-core';
import {
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';

const connect = builders
.connect()
.action(async function () {
const response = await getAddress();
const address = response.result?.address || '';
console.log({ response });

const formattedAccount = CAIP.AccountId.format({
address,
chainId: {
namespace: CAIP_NAMESPACE,
reference: CAIP_SOLANA_CHAIN_ID,
},
}) as CaipAccount;
return [formattedAccount];
})
.build();

const solana = new NamespaceBuilder<SolanaActions>('Solana', WALLET_ID)
.action(connect)
.build();

export { solana };
27 changes: 27 additions & 0 deletions wallets/provider-gemwallet/src/provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { isInstalled } from '@gemwallet/api';
import { ProviderBuilder } from '@rango-dev/wallets-core';

import { info, WALLET_ID } from './constants.js';
import { solana } from './namespaces/solana.js';

const buildProvider = () =>
new ProviderBuilder(WALLET_ID)
.init(function (context) {
const [, setState] = context.state();

window.addEventListener('load', () => {
isInstalled()
.then((response) => {
if (response.result.isInstalled) {
setState('installed', true);
console.debug('[gemwallet] instance detected.', context);
}
})
.catch(console.error);
});
})
.config('info', info)
.add('solana', solana)
.build();

export { buildProvider };
1 change: 1 addition & 0 deletions wallets/provider-gemwallet/src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type Provider = Map<string, unknown>;
12 changes: 12 additions & 0 deletions wallets/provider-gemwallet/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
// see https://www.typescriptlang.org/tsconfig to better understand tsconfigs
"extends": "../../tsconfig.libnext.json",
"include": ["src", "types"],
"files": ["../../global-wallets-env.d.ts"],
"compilerOptions": {
"outDir": "dist",
"rootDir": "./src",
"lib": ["dom", "esnext"]
// match output dir to input dir. e.g. dist/index instead of dist/src/index
}
}
1 change: 1 addition & 0 deletions wallets/provider-gemwallet/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "./tsconfig.build.json", "include": ["src", "tests"] }
Loading
Loading