Skip to content

Commit

Permalink
fix: coinbase not working on first connection (RabbyHub#1903)
Browse files Browse the repository at this point in the history
heisenberg-2077 authored Dec 7, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 791f1b7 commit 861a694
Showing 2 changed files with 21 additions and 7 deletions.
22 changes: 19 additions & 3 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
@@ -3441,9 +3441,12 @@ export class WalletController extends BaseController {
notificationService.setStatsData(data);
};

connectCoinbase = async (curStashId?: number | null) => {
_currentCoinbaseStashId?: undefined | null | number;

connectCoinbase = async () => {
let keyring: CoinbaseKeyring, isNewKey;
const keyringType = KEYRING_CLASS.COINBASE;
const curStashId = this._currentCoinbaseStashId;
try {
if (curStashId !== null && curStashId !== undefined) {
keyring = stashKeyrings[curStashId];
@@ -3463,6 +3466,17 @@ export class WalletController extends BaseController {
if (isNewKey) {
stashId = this.addKeyringToStash(keyring);

eventBus.addEventListener(EVENTS.WALLETCONNECT.INIT, ({ address }) => {
const uri = keyring.connect({
address,
});

eventBus.emit(EVENTS.broadcastToUI, {
method: EVENTS.WALLETCONNECT.INITED,
params: { uri },
});
});

keyring.on('message', (data) => {
if (data.status === 'CHAIN_CHANGED') {
eventBus.emit(EVENTS.broadcastToUI, {
@@ -3487,12 +3501,14 @@ export class WalletController extends BaseController {

const uri = await keyring.connect();

return { uri, stashId };
this._currentCoinbaseStashId = stashId;
return { uri };
};

importCoinbase = async (address: string, stashId?: number) => {
importCoinbase = async (address: string) => {
let keyring: CoinbaseKeyring, isNewKey;
const keyringType = KEYRING_CLASS.COINBASE;
const stashId = this._currentCoinbaseStashId;
try {
keyring = this._getKeyringByType(keyringType);
} catch {
6 changes: 2 additions & 4 deletions src/ui/views/ImportCoinbase/ImportCoinbase.tsx
Original file line number Diff line number Diff line change
@@ -25,7 +25,6 @@ export const ImportCoinbase = () => {
const [runParams, setRunParams] = useState<
Parameters<typeof run> | undefined
>();
const [curStashId, setCurStashId] = useState<number | null>();

const [run, loading] = useWalletRequest(wallet.importCoinbase, {
onSuccess(accounts) {
@@ -57,8 +56,7 @@ export const ImportCoinbase = () => {
};

const handleImportCoinbase = async () => {
const { stashId, uri } = await wallet.connectCoinbase(curStashId);
setCurStashId(stashId);
const { uri } = await wallet.connectCoinbase();
setWalletconnectUri(uri!);
};

@@ -90,7 +88,7 @@ export const ImportCoinbase = () => {
switch (status) {
case SESSION_STATUS_MAP.CONNECTED:
setResult(account.address);
setRunParams([account, curStashId === null ? undefined : curStashId]);
setRunParams([account]);
break;
case SESSION_STATUS_MAP.REJECTED:
handleImportCoinbase();

0 comments on commit 861a694

Please sign in to comment.