@@ -19,7 +19,6 @@ import {
1919 setStoredInvites,
2020} from 'store/storage/roller';
2121import { usePointCache } from 'store/pointCache';
22−import { getOutgoingPoints } from 'views/Points';
2322
2423import { getUpdatedPointMessage, isPlanet, toL1Details } from './utils/point';
2524import { convertToInt } from './convertToInt';
@@ -30,9 +29,6 @@ import {
3029 submitL2Transaction,
3130 getTimeToNextBatch,
3231 registerProxyAddress,
33− adopt,
34− detach,
35− reject,
3632 isL2Spawn,
3733} from './utils/roller';
3834import { ETH_ZERO_ADDR, ROLLER_HOSTS, TEN_SECONDS } from './constants';
@@ -81,7 +77,6 @@ export default function useRoller() {
8177 const { pointCursor }: any = usePointCursor();
8278 const { web3, contracts }: any = useNetwork();
8379 const allPoints: any = usePointCache();
84− const controlledPoints = allPoints?.controlledPoints;
8580 const getDetails = allPoints?.getDetails;
8681
8782 const { setNextRoll } = useTimerStore();
@@ -90,6 +85,7 @@ export default function useRoller() {
9085 nextBatchTime,
9186 point,
9287 points,
88+ pointList,
9389 nextQuotaTime,
9490 removeInvite,
9591 setNextBatchTime,
@@ -263,7 +259,7 @@ export default function useRoller() {
263259 );
264260
265261 const spawnPoint = useCallback(
266− async (pointToSpawn: number) => {
262+ async (pointToSpawn: number, destinationAddress: string) => {
267263 if (quotaReached()) {
268264 return;
269265 }
@@ -291,7 +287,7 @@ export default function useRoller() {
291287
292288 await submitL2Transaction({
293289 api,
294− address: _wallet.address,
290+ address: destinationAddress,
295291 wallet: _wallet,
296292 ship: _point,
297293 proxy,
@@ -347,10 +343,11 @@ export default function useRoller() {
347343 curPoint
348344 );
349345
350− const outgoingPoints = getOutgoingPoints(
351− controlledPoints,
352− getDetails
353− ).filter((p: number) => isPlanet(p) && availablePoints.includes(p));
346+ const outgoingPoints = pointList
347+ .filter(
348+ ({ value, isPlanet }) => isPlanet && availablePoints.includes(value)
349+ )
350+ .map(({ value }) => value);
354351
355352 const invitePlanets = spawnedPoints
356353 .concat(
@@ -405,11 +402,10 @@ export default function useRoller() {
405402 api,
406403 authToken,
407404 contracts,
408− controlledPoints,
409− getDetails,
410405 pointCursor,
411406 ls,
412407 point,
408+ pointList,
413409 removeInvite,
414410 setInvites,
415411 setInvitesLoading,
@@ -789,75 +785,40 @@ export default function useRoller() {
789785 [api, connector, point, wallet, web3, walletType, quotaReached]
790786 );
791787
792− const adoptPoint = useCallback(
793− async (ship: Ship) => {
788+ const changeSponsorship = useCallback(
789+ async (sponsee: Ship, type: 'adopt' | 'detach' | 'reject') => {
794790 if (quotaReached()) {
795791 return;
796792 }
797793
798794 const _wallet = wallet.getOrElse(null);
795+ const _web3 = web3.getOrElse(null);
796+ const ship = point.value;
799797
800798 const proxy = point.getManagerProxy();
801799
802800 if (proxy === undefined)
803801 throw new Error("Error: Address doesn't match expected proxy");
804802
805− const nonce = await api.getNonce({ ship: point.value, proxy });
806− const txHash = await adopt(api, _wallet, point.value, proxy, nonce, ship);
807−
808− return api.getPendingTx(txHash);
809− },
810− [api, point, wallet, quotaReached]
811− );
812−
813− const kickPoint = useCallback(
814− async (ship: Ship) => {
815− if (quotaReached()) {
816− return;
817− }
818−
819− if (point.isDefault) {
820− throw new Error('Internal Error: point is default');
821− }
822−
823− const sponsor = point.value;
824− const _wallet = wallet.getOrElse(null);
825− const proxy = point.getManagerProxy();
826−
827− if (proxy === undefined)
828− throw new Error("Error: Address doesn't match expected proxy");
829−
830− const nonce = await api.getNonce({ ship: sponsor, proxy });
831− const txHash = await detach(api, _wallet, sponsor, proxy, nonce, ship);
832−
833− return api.getPendingTx(txHash);
834− },
835− [api, point, wallet, quotaReached]
836− );
837−
838− const rejectPoint = useCallback(
839− async (ship: Ship) => {
840− if (quotaReached()) {
841− return;
842− }
843−
844− if (point.isDefault) {
845− throw new Error('Internal Error: point is default');
846− }
847−
848− const sponsor = point.value;
849− const _wallet = wallet.getOrElse(null);
850− const proxy = point.getManagerProxy();
851−
852− if (proxy === undefined)
853− throw new Error("Error: Address doesn't match expected proxy");
854−
855− const nonce = await api.getNonce({ ship: sponsor, proxy });
856− const txHash = await reject(api, _wallet, sponsor, proxy, nonce, ship);
803+ const nonce = await api.getNonce({ ship, proxy });
804+ // const txHash = await adopt(api, _wallet, point.value, proxy, nonce, ship);
805+ const txHash = await submitL2Transaction({
806+ api,
807+ wallet: _wallet,
808+ ship,
809+ sponsee,
810+ proxy,
811+ nonce,
812+ address: _wallet.address,
813+ type,
814+ walletType,
815+ web3: _web3,
816+ connector,
817+ });
857818
858819 return api.getPendingTx(txHash);
859820 },
860− [api, point, wallet, quotaReached]
821+ [api, point, wallet, walletType, web3, connector, quotaReached]
861822 );
862823
863824 const transferPoint = useCallback(
@@ -960,6 +921,34 @@ export default function useRoller() {
960921 [api, point, sendL2Transaction, wallet]
961922 );
962923
924+ const cancelEscape = useCallback(async () => {
925+ if (point.isDefault) {
926+ throw new Error('Internal Error: point is default');
927+ }
928+
929+ const curPoint = point.value;
930+ const _wallet = wallet.getOrElse(null);
931+
932+ if (!_wallet) {
933+ // not using need because we want a custom error
934+ throw new Error('Internal Error: Missing Wallet');
935+ }
936+
937+ const proxy = point.getManagerProxy();
938+
939+ if (proxy === undefined)
940+ throw new Error("Error: Address doesn't match proxy");
941+
942+ const nonce = await api.getNonce({ ship: curPoint, proxy });
943+
944+ return sendL2Transaction({
945+ nonce,
946+ proxy,
947+ type: 'cancelEscape',
948+ ship: curPoint,
949+ });
950+ }, [api, point, sendL2Transaction, wallet]);
951+
963952 const getPointsDetails = useCallback(
964953 async (
965954 ownedPoints: number[],
@@ -1029,9 +1018,10 @@ export default function useRoller() {
10291018 }, [point, nextBatchTime, getPendingTransactions, getInvites]); // eslint-disable-line react-hooks/exhaustive-deps
10301019
10311020 return {
1032− adoptPoint,
10331021 api,
1022+ changeSponsorship,
10341023 changeSponsor,
1024+ cancelEscape,
10351025 checkForUpdates,
10361026 config,
10371027 configureNetworkingKeys,
@@ -1040,10 +1030,8 @@ export default function useRoller() {
10401030 getPoints,
10411031 getPointsDetails,
10421032 getPendingTransactions,
1043− kickPoint,
10441033 ls,
10451034 performL2Reticket,
1046− rejectPoint,
10471035 setProxyAddress,
10481036 spawnPoint,
10491037 transferPoint,