Skip to content
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

fix: silently connect with argentX #865

Draft
wants to merge 5 commits into
base: master
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: 1 addition & 1 deletion apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"remove-markdown": "^0.5.2",
"scrollmonitor": "^1.2.11",
"starknet": "6.11.0",
"starknetkit": "^1.1.9",
"starknetkit": "^2.3.2",
"stream-browserify": "^3.0.0",
"tippy.js": "^6.3.7",
"turndown": "^7.2.0",
Expand Down
45 changes: 34 additions & 11 deletions apps/ui/src/helpers/argentx.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,69 @@
import LockConnector from '@snapshot-labs/lock/src/connector';
import { useUserSkin } from '@/composables/useUserSkin';
import { APP_NAME } from './constants';
const get = () => import(/* webpackChunkName: "argentx" */ 'starknetkit');

const CONNECTOR_NAME = 'argentx';

const { currentMode } = useUserSkin();

export default class Connector extends LockConnector {
async connect() {
let provider;
async connect(): Promise<any> {
let provider: any;

try {
const argentx = await get();
const starknet = await argentx.connect({
dappName: 'Snapshot',
const { wallet } = await argentx.connect({
dappName: APP_NAME,
modalMode: localStorage.getItem('starknetLastConnectedWallet')
? 'neverAsk'
: 'alwaysAsk',
modalTheme: currentMode.value,
argentMobileOptions: {
dappName: 'Snapshot',
dappName: APP_NAME,
url: 'https://snapshot.box',
icons: ['https://snapshot.box/favicon.svg']
}
});

if (!starknet.wallet) {
if (!wallet) {
throw Error(
'User rejected wallet selection or silent connect found nothing'
);
}

if (!starknet.wallet.isConnected) {
throw new Error('Connector was not connected');
}
// @ts-ignore
if (!wallet.isConnected) await wallet?.enable();

provider = wallet;
provider.connectorName = CONNECTOR_NAME;

provider = starknet.wallet;
provider.connectorName = 'argentx';
return provider;
} catch (e) {
console.error(e);
return false;
}
}

async autoConnect() {
let provider: any = null;

try {
const argentx = await get();
const { wallet } = await argentx.connect({ modalMode: 'neverAsk' });

// @ts-ignore
if (!wallet.isConnected) await wallet?.enable();

provider = wallet;
provider.connectorName = CONNECTOR_NAME;

return provider;
} catch (e) {
return false;
}
}

async logout() {
const argentx = await get();
await argentx.disconnect({
Expand Down
Loading
Loading