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

Substrate walletconnect #1451

Merged
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
516de2c
initial settings
Nikita-Polyakov Jun 24, 2024
38e3936
patch EthereumProvider
Nikita-Polyakov Jun 27, 2024
ef8b189
add types to WcEthereumProvider
Nikita-Polyakov Jun 27, 2024
74f3c46
update login & logout for sub bridge
Nikita-Polyakov Jun 28, 2024
aa4abd0
return reactivity to accountApi
Nikita-Polyakov Jul 1, 2024
e491e06
Merge remote-tracking branch 'origin/develop' into feature/substrate-…
Nikita-Polyakov Jul 1, 2024
eac2bc8
update wallet
Nikita-Polyakov Jul 1, 2024
405ca47
remove log
Nikita-Polyakov Jul 1, 2024
b2b56d8
merge origin/develop
Nikita-Polyakov Jul 5, 2024
f3b2318
fix wc ethereum modal
Nikita-Polyakov Jul 5, 2024
c6688c7
update wallet
Nikita-Polyakov Jul 5, 2024
3a506d9
Merge branch 'develop' into feature/substrate-walletconnect
C4tWithShell Jul 5, 2024
9193ec2
Merge branch 'develop' into feature/substrate-walletconnect
Naghme98 Jul 7, 2024
c1b4aa7
Fix soraneo-wallet-web version
C4tWithShell Jul 8, 2024
10428bf
Merge branch 'develop' into feature/substrate-walletconnect
C4tWithShell Jul 8, 2024
b18a82d
Merge branch 'develop' into feature/substrate-walletconnect
Nikita-Polyakov Jul 11, 2024
da38ae4
update wc modal z-index
Nikita-Polyakov Jul 11, 2024
859e0a7
Merge branch 'feature/substrate-walletconnect' of github.com:sora-xor…
Nikita-Polyakov Jul 11, 2024
d21bd5e
update wallet 1.39.1
Nikita-Polyakov Jul 12, 2024
153fee0
update ts version
Nikita-Polyakov Jul 12, 2024
cb39113
Merge branch 'develop' into feature/substrate-walletconnect
Nikita-Polyakov Jul 16, 2024
ecb96b5
Merge remote-tracking branch 'origin/develop' into feature/substrate-…
Nikita-Polyakov Jul 17, 2024
fc3685f
Merge branch 'develop' into feature/substrate-walletconnect
Nikita-Polyakov Jul 18, 2024
9ec6cfb
Merge branch 'develop' into feature/substrate-walletconnect
Nikita-Polyakov Jul 19, 2024
c86f049
update wallet 1.39.4
Nikita-Polyakov Jul 19, 2024
b463fdb
update wallet 1.39.5
Nikita-Polyakov Jul 19, 2024
b4f0021
update SubscriptionsMixin
Nikita-Polyakov Jul 22, 2024
8830550
Merge branch 'develop' into feature/substrate-walletconnect
Nikita-Polyakov Jul 23, 2024
5af5673
Merge branch 'develop' into feature/substrate-walletconnect
Nikita-Polyakov Jul 23, 2024
8613712
Merge remote-tracking branch 'origin/develop' into feature/substrate-…
Nikita-Polyakov Jul 24, 2024
8bc1932
update wallet 1.39.7
Nikita-Polyakov Jul 25, 2024
c75be54
restore wc ethereum session
Nikita-Polyakov Jul 29, 2024
8b118d1
Merge branch 'develop' into feature/substrate-walletconnect
C4tWithShell Jul 29, 2024
ba1d1c7
update expiry
Nikita-Polyakov Jul 29, 2024
c1fd033
Merge branch 'feature/substrate-walletconnect' of github.com:sora-xor…
Nikita-Polyakov Jul 29, 2024
f20a115
Merge branch 'develop' into feature/substrate-walletconnect
stefashkaa Aug 1, 2024
226db5a
Update package.json
Aug 1, 2024
98e28c3
Fix lint issues
Aug 1, 2024
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
Prev Previous commit
Next Next commit
update expiry
  • Loading branch information
Nikita-Polyakov committed Jul 29, 2024
commit ba1d1c7ef0869ce96c29bbfca78d8ea616d54a03
29 changes: 3 additions & 26 deletions src/utils/walletconnect.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { WC } from '@soramitsu/soraneo-wallet-web';
import { EthereumProvider } from '@walletconnect/ethereum-provider';
import { UniversalProvider } from '@walletconnect/universal-provider';

import type {
ChainsProps,
Expand All @@ -9,24 +8,6 @@ import type {
} from '@walletconnect/ethereum-provider/dist/types/EthereumProvider';
import type { SessionTypes } from '@walletconnect/types';

function getAccountsFromNamespaces(namespaces: SessionTypes.Namespaces, keys: string[] = []): string[] {
const accounts: string[] = [];
Object.keys(namespaces).forEach((key) => {
if (keys.length && !keys.includes(key)) return;
const ns = namespaces[key];
accounts.push(...ns.accounts);
});
return accounts;
}

function getEthereumChainId(chains: string[]): number {
return Number(chains[0].split(':')[1]);
}

function toHexChainId(chainId: number): string {
return `0x${chainId.toString(16)}`;
}

export class WcEthereumProvider extends EthereumProvider {
/**
* "Init" is overrided to return the instance of this child class
Expand Down Expand Up @@ -64,18 +45,14 @@ export class WcEthereumProvider extends EthereumProvider {
if (!(Array.isArray(sessionChains) && sessionChains.includes(chainId))) continue;

const pairingTopic = session.pairingTopic;
const expiry = Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 7;
try {
console.info(`[${this.constructor.name}]: active pairing found: "${pairingTopic}"`);
await this.signer.client.core.pairing.activate({ topic: pairingTopic });
console.info(`[${this.constructor.name}]: pairing activated: "${pairingTopic}"`);
await this.signer.client.core.pairing.updateExpiry({ topic: pairingTopic, expiry });
console.info(`[${this.constructor.name}]: pairing expiry updated: "${pairingTopic}"`);
this.setAppSession(session);

const accounts = getAccountsFromNamespaces(session.namespaces, [this.namespace]);
// if no required chains are set, use the approved accounts to fetch chainIds
this.setChainIds(this.rpc.chains.length ? this.rpc.chains : accounts);
this.setAccounts(accounts);
this.events.emit('connect', { chainId: toHexChainId(this.chainId) });

return;
} catch {
console.info(
Expand Down