Skip to content

Commit e088ca6

Browse files
wa0x6eChaituVRSekhmet
authored
feat: add support for starknet account to offchain actions (#383)
* feat: add setAlias to starknet eth sign * fix: use starknet-sig instead of ethereum-sig * fix: fix signature schema * fix: update type to include optional properties * fix: more robust starknet wallet detection * fix: enable back follow button for starknet wallet * fix: fix typing * feat: add support for starknet signature for offchain `send` * fix: use string type to allow starknet address * fix: enable space following/unfollowing for starknet wallets * fix: enable user profile edition for starknet users * fix: use formatted address in alias from * fix: always use padded starknet address * fix: sign sn createAlias on the correct chainId * chore: fix tests * fix: avoid loading votes from incompatible networks * fix: add types and domain to starknet envelope * Update apps/ui/src/composables/useActions.ts Co-authored-by: Chaitanya <[email protected]> * fix: revert unrelated change * chore: removed unused import * chore: add comments about confusing extra starknet params on evm envelope * chore: fix import order * fix: sign alias with first available starknet network * chore: lint fix * chore: add changesets * revert: revert back ot use correct starknet chaind ID * fix: finish revert * fix: fix leftover from merge * refactor: simplify starknetNetworkId lookup --------- Co-authored-by: Chaitanya <[email protected]> Co-authored-by: Wiktor Tkaczyński <[email protected]>
1 parent f1e3b13 commit e088ca6

File tree

17 files changed

+339
-41
lines changed

17 files changed

+339
-41
lines changed

.changeset/calm-deers-sort.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@snapshot-labs/sx": patch
3+
---
4+
5+
add domain and types to starknet/starknet-sig envelope

.changeset/funny-candles-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@snapshot-labs/sx": patch
3+
---
4+
5+
always return padded addresses in starknet/starknet-sig envelope

.changeset/red-mayflies-yell.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@snapshot-labs/sx": patch
3+
---
4+
5+
add support for sending starknet signed message to offchain/ethereum-sig

.changeset/wild-news-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@snapshot-labs/sx": patch
3+
---
4+
5+
add setAlias to starknet/starknet-sig

apps/ui/src/components/ButtonFollow.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ const { isSafeWallet } = useSafeWallet(
1212
props.space.snapshot_chain_id
1313
);
1414
const followedSpacesStore = useFollowedSpacesStore();
15-
const { web3 } = useWeb3();
1615
1716
const spaceFollowed = computed(() =>
1817
followedSpacesStore.isFollowed(spaceIdComposite)
1918
);
20-
const hidden = computed(() => web3.value?.type === 'argentx');
2119
2220
const loading = computed(
2321
() =>
@@ -28,7 +26,6 @@ const loading = computed(
2826

2927
<template>
3028
<UiButton
31-
v-if="!hidden"
3229
:disabled="loading || isSafeWallet"
3330
class="group"
3431
:class="{ 'hover:border-skin-danger': spaceFollowed }"

apps/ui/src/composables/useActions.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
import { getInstance } from '@snapshot-labs/lock/plugins/vue3';
22
import { registerTransaction } from '@/helpers/mana';
33
import { convertToMetaTransactions } from '@/helpers/transactions';
4-
import { getNetwork, getReadWriteNetwork, metadataNetwork } from '@/networks';
4+
import {
5+
enabledNetworks,
6+
getNetwork,
7+
getReadWriteNetwork,
8+
metadataNetwork,
9+
starknetNetworks
10+
} from '@/networks';
11+
import { STARKNET_CONNECTORS } from '@/networks/common/constants';
512
import { Connector, StrategyConfig } from '@/networks/types';
613
import {
714
Choice,
@@ -16,6 +23,13 @@ import {
1623
VoteType
1724
} from '@/types';
1825

26+
const offchainToStarknetIds: Record<string, NetworkID> = {
27+
s: 'sn',
28+
's-tn': 'sn-sep'
29+
};
30+
31+
const starknetNetworkId = offchainToStarknetIds[metadataNetwork];
32+
1933
export function useActions() {
2034
const { mixpanel } = useMixpanel();
2135
const uiStore = useUiStore();
@@ -126,7 +140,11 @@ export function useActions() {
126140
}
127141

128142
async function getAliasSigner() {
129-
const network = getNetwork(metadataNetwork);
143+
const network = getNetwork(
144+
STARKNET_CONNECTORS.includes(web3.value.type as Connector)
145+
? starknetNetworkId
146+
: metadataNetwork
147+
);
130148

131149
return alias.getAliasWallet(address =>
132150
wrapPromise(metadataNetwork, network.actions.setAlias(auth.web3, address))

apps/ui/src/networks/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const evmNetworks: NetworkID[] = [
2929
'linea-testnet'
3030
];
3131
export const offchainNetworks: NetworkID[] = ['s', 's-tn'];
32+
export const starknetNetworks: NetworkID[] = ['sn', 'sn-sep'];
3233
// This network is used for aliases/follows/profiles/explore page.
3334
export const metadataNetwork: NetworkID =
3435
import.meta.env.VITE_METADATA_NETWORK || 's';

apps/ui/src/networks/starknet/actions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,12 @@ export function createActions(
658658
},
659659
followSpace: () => {},
660660
unfollowSpace: () => {},
661-
setAlias: () => {},
661+
setAlias(web3: any, alias: string) {
662+
return starkSigClient.setAlias({
663+
signer: web3.provider.account,
664+
data: { alias }
665+
});
666+
},
662667
updateUser: () => {},
663668
updateStatement: () => {},
664669
send: (envelope: any) => starkSigClient.send(envelope) // TODO: extract it out of client to common helper

apps/ui/src/stores/followedSpaces.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,15 @@ export const useFollowedSpacesStore = defineStore('followedSpaces', () => {
128128
watch(
129129
[
130130
() => web3.value.account,
131-
() => web3.value.type,
132131
() => web3.value.authLoading,
133132
() => authInitiated.value
134133
],
135-
async ([web3, walletType, authLoading, authInitiated]) => {
134+
async ([web3, authLoading, authInitiated]) => {
136135
if (!authInitiated || authLoading) return;
137136

138137
followedSpacesLoaded.value = false;
139138

140-
if (!web3 || walletType === 'argentx') {
139+
if (!web3) {
141140
followedSpacesIds.value = [];
142141
followedSpacesLoaded.value = true;
143142
return;

apps/ui/src/views/User.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,7 @@ watchEffect(() => setTitle(`${user.value?.name || id.value} user profile`));
130130
/>
131131
<div class="absolute right-4 top-4 space-x-2 flex">
132132
<DropdownShare :message="shareMsg" class="!px-0 w-[46px]" />
133-
<UiTooltip
134-
v-if="web3.account === user.id && web3.type !== 'argentx'"
135-
title="Edit profile"
136-
>
133+
<UiTooltip v-if="web3.account === user.id" title="Edit profile">
137134
<UiButton class="!px-0 w-[46px]" @click="modalOpenEditUser = true">
138135
<IH-cog class="inline-block" />
139136
</UiButton>

0 commit comments

Comments
 (0)