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: argent mobile wallet isse #426

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
58 changes: 25 additions & 33 deletions apps/mobile/src/app/StarknetProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,87 +2,79 @@ import {mainnet, sepolia} from '@starknet-react/chains';
import {
argent,
braavos,
publicProvider,
StarknetConfig,
useInjectedConnectors,
voyager,
} from '@starknet-react/core';
import {kakarotConnectors} from '@starknet-react/kakarot';
// import {ConnectorProvider as StarknetWCProvider} from '@starknet-wc/react';
import {Platform} from 'react-native';
// import { ArgentMobileConnector, isInArgentMobileAppBrowser } from "starknetkit/argentMobile"
// import { InjectedConnector } from "starknetkit/injected"
// import { WebWalletConnector } from "starknetkit/webwallet"
import {ArgentMobileConnector, isInArgentMobileAppBrowser} from 'starknetkit/argentMobile';
import {WebWalletConnector} from 'starknetkit/webwallet';

import {NETWORK_NAME} from '../constants/env';
import {CHAIN_ID, NETWORK_NAME} from '../constants/env';
import {RpcProviderProvider} from '../context/RpcProvider';
// import {WalletQRModal} from '../modules/WalletQRModal';
import {providers} from '../services/provider';

import {ArgentMobileConnector, isInArgentMobileAppBrowser} from 'starknetkit/argentMobile';
import {InjectedConnector} from 'starknetkit/injected';
import {WebWalletConnector} from 'starknetkit/webwallet';

export const StarknetReactProvider: React.FC<React.PropsWithChildren> = ({children}) => {
const chain = {
SN_MAIN: mainnet,
SN_SEPOLIA: sepolia,
}[NETWORK_NAME];

const provider = providers(chain);
const providerRpc = publicProvider();
// const providerRpc = publicProvider();
// const argentMobileConnector = useArgentMobileConnector();

const recommended =
Platform.OS === 'web'
? [argent(), braavos(), ...kakarotConnectors(providerRpc)]
? [
argent(),
braavos(),
// ...kakarotConnectors(providerRpc)
]
: [argent(), braavos()];

const chains = [mainnet, sepolia];
// const connectors = [
// new InjectedConnector({ options: { id: "braavos", name: "Braavos" }}),
// new InjectedConnector({ options: { id: "argentX", name: "Argent X" }}),
// new WebWalletConnector({ url: "https://web.argent.xyz" }),
// new ArgentMobileConnector(),
// ]
const {connectors: injected} = useInjectedConnectors({
recommended,
includeRecommended: 'always',
order: 'alphabetical',
// Randomize the order of the connectors.
// order: "alphabetical",
});
const connectorInjected = injected;

const connectors = isInArgentMobileAppBrowser()
const mobileConnector = isInArgentMobileAppBrowser()
? [
ArgentMobileConnector.init({
options: {
dappName: 'AFK Dapp',
projectId: process.env.EXPO_PUBLIC_WC_ID ?? 'example-project-id',
url: typeof window !== 'undefined' ? window.location.href : '',
chainId: CHAIN_ID as any,
},
inAppBrowserOptions: {},
}),
]
: [
new InjectedConnector({options: {id: 'braavos', name: 'Braavos'}}),
new InjectedConnector({options: {id: 'argentX', name: 'Argent X'}}),
new WebWalletConnector({url: 'https://web.argent.xyz'}),
...connectorInjected,
ArgentMobileConnector.init({
options: {
url: typeof window !== 'undefined' ? window.location.href : '',
dappName: 'AFK Dapp',
chainId: CHAIN_ID as any,
projectId: process.env.EXPO_PUBLIC_WC_ID ?? 'example-project-id',
},
}),
new WebWalletConnector({url: 'https://web.argent.xyz'}),
];

const {connectors: injected} = useInjectedConnectors({
recommended,
includeRecommended: 'always',
order: 'alphabetical',
// Randomize the order of the connectors.
// order: "alphabetical",
});

return (
<RpcProviderProvider provider={provider}>
<StarknetConfig
chains={[chain]}
provider={providers}
autoConnect
connectors={connectors}
connectors={mobileConnector}
// connectors={[...(Platform.OS === 'web' ? injected : [])]}
explorer={voyager}
>
Expand Down
Loading