on master help sign in
proxies: add getProxy functions
dd02fcdyosoyubik
src/lib/useRoller.ts+8−31
@@ -23,10 +23,10 @@ import {
23import { usePointCache } from 'store/pointCache';
23import { usePointCache } from 'store/pointCache';
24import { getOutgoingPoints } from 'views/Points';
24import { getOutgoingPoints } from 'views/Points';
25import {
25import {
26− isManagementProxy,
26+ getSpawnProxy,
27− isOwnerProxy,
27+ getManagerProxy,
28− isTransferProxy,
28+ getAddressProxy,
29− isSpawnProxy,
29+ getTransferProxy,
30} from './utils/proxy';
30} from './utils/proxy';
31import { isPlanet } from './utils/point';
31import { isPlanet } from './utils/point';
32
32
@@ -165,11 +165,7 @@ export default function useRoller() {
165 }[] = [];
165 }[] = [];
166 const requests: Promise<string>[] = [];
166 const requests: Promise<string>[] = [];
167
167
168− const proxy = isOwnerProxy(starInfo.ownership!, _wallet.address)
169− ? 'own'
170− : isSpawnProxy(starInfo.ownership!, _wallet.address)
168+ const proxy = getSpawnProxy(starInfo.ownership!, _wallet.address);
171− ? 'spawn'
172− : undefined;
173
169
174 if (proxy === undefined)
170 if (proxy === undefined)
175 throw new Error("Error: Address doesn't match proxy");
171 throw new Error("Error: Address doesn't match proxy");
@@ -429,12 +425,7 @@ export default function useRoller() {
429 }
425 }
430
426
431 const pointDetails = await api.getPoint(_point);
427 const pointDetails = await api.getPoint(_point);
432− // const proxy = getProxy(pointDetails.ownership!, _wallet.address);
433− const proxy = isOwnerProxy(pointDetails.ownership!, _wallet.address)
434− ? 'own'
435− : isManagementProxy(pointDetails.ownership!, _wallet.address)
428+ const proxy = getManagerProxy(pointDetails.ownership!, _wallet.address);
436− ? 'manage'
437− : undefined;
438
429
439 if (proxy === undefined)
430 if (proxy === undefined)
440 throw new Error("Error: Address doesn't match proxy");
431 throw new Error("Error: Address doesn't match proxy");
@@ -564,17 +555,7 @@ export default function useRoller() {
564
555
565 const pointDetails = await api.getPoint(_point);
556 const pointDetails = await api.getPoint(_point);
566 const ownership = pointDetails.ownership!;
557 const ownership = pointDetails.ownership!;
567− const proxy = isOwnerProxy(ownership, _wallet.address)
558+ const proxy = getAddressProxy(ownership, _wallet.address, proxyType);
568− ? 'own'
569− : proxyType === 'manage' &&
570− isManagementProxy(ownership, _wallet.address)
571− ? 'manage'
572− : proxyType === 'spawn' && isSpawnProxy(ownership, _wallet.address)
573− ? 'spawn'
574− : proxyType === 'transfer' &&
575− isTransferProxy(ownership, _wallet.address)
576− ? 'transfer'
577− : undefined;
578
559
579 if (proxy === undefined)
560 if (proxy === undefined)
580 throw new Error("Error: Address doesn't match expected proxy");
561 throw new Error("Error: Address doesn't match expected proxy");
@@ -609,11 +590,7 @@ export default function useRoller() {
609 }
590 }
610
591
611 const pointDetails = await api.getPoint(_point);
592 const pointDetails = await api.getPoint(_point);
612− const proxy = isOwnerProxy(pointDetails.ownership!, _wallet.address)
613− ? 'own'
614− : isTransferProxy(pointDetails.ownership!, _wallet.address)
593+ const proxy = getTransferProxy(pointDetails.ownership!, _wallet.address);
615− ? 'transfer'
616− : undefined;
617
594
618 if (proxy === undefined)
595 if (proxy === undefined)
619 throw new Error("Error: Address doesn't match proxy");
596 throw new Error("Error: Address doesn't match proxy");
src/lib/utils/proxy.ts+41−25
@@ -1,33 +1,49 @@
1−import { Ownership } from '@urbit/roller-api';
1+import { Ownership, Proxy } from '@urbit/roller-api';
2
2
3−// TODO: test when all proxies are configured to the same address
4−export const getProxy = (
5− owner: Ownership,
6− address: string
7−): string | undefined =>
8− owner.owner?.address === address
9− ? 'own'
10− : owner.managementProxy?.address === address
11− ? 'manage'
12− : owner.spawnProxy?.address === address
13− ? 'spawn'
14− : owner.votingProxy?.address === address
15− ? 'vote'
16− : owner.transferProxy?.address === address
17− ? 'transfer'
18− : undefined;
19−
20−export const isManagementProxy = (owner: Ownership, address: string) =>
3+const isManagementProxy = (owner: Ownership, address: string) =>
21 owner.managementProxy?.address === address;
4 owner.managementProxy?.address === address;
22
5
23−export const isTransferProxy = (owner: Ownership, address: string) =>
6+const isTransferProxy = (owner: Ownership, address: string) =>
24 owner.transferProxy?.address === address;
7 owner.transferProxy?.address === address;
25
8
26−export const isVotingProxy = (owner: Ownership, address: string) =>
27− owner.votingProxy?.address === address;
28−
29−export const isSpawnProxy = (owner: Ownership, address: string) =>
9+const isSpawnProxy = (owner: Ownership, address: string) =>
30 owner.spawnProxy?.address === address;
10 owner.spawnProxy?.address === address;
31
11
32−export const isOwnerProxy = (owner: Ownership, address: string) =>
12+const isOwnerProxy = (owner: Ownership, address: string) =>
33 owner.owner?.address === address;
13 owner.owner?.address === address;
14+
15+export const getSpawnProxy = (owner: Ownership, address: string) =>
16+ isOwnerProxy(owner, address)
17+ ? 'own'
18+ : isSpawnProxy(owner, address)
19+ ? 'spawn'
20+ : undefined;
21+
22+export const getManagerProxy = (owner: Ownership, address: string) =>
23+ isOwnerProxy(owner, address)
24+ ? 'own'
25+ : isManagementProxy(owner, address)
26+ ? 'manage'
27+ : undefined;
28+
29+export const getAddressProxy = (
30+ owner: Ownership,
31+ address: string,
32+ proxyType: Proxy
33+) =>
34+ isOwnerProxy(owner, address)
35+ ? 'own'
36+ : proxyType === 'manage' && isManagementProxy(owner, address)
37+ ? 'manage'
38+ : proxyType === 'spawn' && isSpawnProxy(owner, address)
39+ ? 'spawn'
40+ : proxyType === 'transfer' && isTransferProxy(owner, address)
41+ ? 'transfer'
42+ : undefined;
43+
44+export const getTransferProxy = (owner: Ownership, address: string) =>
45+ isOwnerProxy(owner, address)
46+ ? 'own'
47+ : isTransferProxy(owner, address)
48+ ? 'transfer'
49+ : undefined;