mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Handle wallet account change (#4)
This commit is contained in:
+14
-1
@@ -1,4 +1,3 @@
|
||||
// TODO: Handle wallet account change.
|
||||
import { get, writable, derived, Writable } from "svelte/store";
|
||||
import { ethers } from "ethers";
|
||||
import type { BigNumber } from 'ethers';
|
||||
@@ -143,6 +142,17 @@ export const createState = (initial: State) => {
|
||||
}
|
||||
});
|
||||
},
|
||||
setChangedAccount: ([address]: string[]) => {
|
||||
store.update(s => {
|
||||
switch (s.connection) {
|
||||
case Connection.Connected:
|
||||
s.session.address = address;
|
||||
return s;
|
||||
default:
|
||||
return s;
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
@@ -154,6 +164,9 @@ export const session = derived(state, s => {
|
||||
return null;
|
||||
});
|
||||
|
||||
// Updates state when user changes accounts
|
||||
window.ethereum?.on("accountsChanged", state.setChangedAccount);
|
||||
|
||||
state.subscribe(s => {
|
||||
console.log("session.state", s);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user