Skip to content

Commit

Permalink
CR refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
NorbertBodziony committed Jun 14, 2022
1 parent 8f6e442 commit 45125a1
Showing 1 changed file with 2 additions and 19 deletions.
21 changes: 2 additions & 19 deletions packages/nightly/src/lib/nightly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,12 @@ const isInstalled = () => {
return waitFor(() => !!window.nightly!.near!).catch(() => false);
};
const Nightly: WalletBehaviourFactory<InjectedWallet> = async ({
metadata,
store,
logger,
provider,
}) => {
const _state = await setupNightlyState(store);

const currentState = store.getState();
if (currentState.selectedWalletId === "nightly") {
try {
// eager connect to the wallet
await _state.wallet.connect(undefined, true);
} catch {
// ignore
}
}
const getAccounts = async () => {
if (!_state || _state.wallet.account.accountId === "") {
return [];
Expand All @@ -68,19 +58,12 @@ const Nightly: WalletBehaviourFactory<InjectedWallet> = async ({
return {
// nightly does not support delegating signing right now
async signIn() {
// If wallet does not exist user will be redirected to download page
if (!_state) {
window.location.href = metadata.downloadUrl;
throw new Error("Redirecting to download");
}
const existingAccount = _state.wallet.account.accountId;

if (existingAccount) {
const nearAccount: Account = {
accountId: _state.wallet.account.accountId,
};
return [nearAccount];
return await getAccounts();
}

await _state.wallet.connect();

return await getAccounts();
Expand Down

0 comments on commit 45125a1

Please sign in to comment.