Fix robot recovery (#945)

* Fix Robot recovery

* Change testralia onion
This commit is contained in:
KoalaSat 2023-11-14 13:24:45 +00:00 committed by Reckless_Satoshi
parent b973afe13e
commit 8d8e3a5688
8 changed files with 59 additions and 39 deletions

View File

@ -9,7 +9,7 @@ interface RecoveryProps {
inputToken: string;
badToken: string;
setInputToken: (state: string) => void;
getGenerateRobot: (token: string) => void;
getRecoverRobot: (token: string) => void;
}
const Recovery = ({
@ -17,12 +17,12 @@ const Recovery = ({
badToken,
setView,
setInputToken,
getGenerateRobot,
getRecoverRobot,
}: RecoveryProps): JSX.Element => {
const { t } = useTranslation();
const onClickRecover = (): void => {
getGenerateRobot(inputToken);
getRecoverRobot(inputToken);
setView('profile');
};

View File

@ -58,7 +58,7 @@ const RobotProfile = ({
if (garage.getRobot().nickname != null && garage.getRobot().avatarLoaded) {
setLoading(false);
}
}, [robotUpdatedAt]);
}, [robotUpdatedAt, loading]);
const handleAddRobot = (): void => {
getGenerateRobot(genBase62Token(36));

View File

@ -48,10 +48,8 @@ const RobotPage = ({ avatarBaseUrl }: RobotPageProps): JSX.Element => {
const token = urlToken ?? garage.getRobot().token;
if (token !== undefined) {
setInputToken(token);
}
if (garage.getRobot().nickname !== undefined && token !== undefined) {
if (window.NativeRobosats === undefined || torStatus === '"Done"') {
getGenerateRobot(token);
getRecoverRobot(token);
setView('profile');
}
}
@ -67,16 +65,32 @@ const RobotPage = ({ avatarBaseUrl }: RobotPageProps): JSX.Element => {
}
}, [inputToken]);
const getGenerateRobot = (token: string): void => {
const getRecoverRobot = (token: string): void => {
setInputToken(token);
genKey(token)
.then((key) => {
const slot = garage.createRobot({
garage.updateRobot({
token,
pubKey: key.publicKeyArmored,
encPrivKey: key.encryptedPrivateKeyArmored,
});
void federation.fetchRobot(garage, slot);
void federation.fetchRobot(garage, garage.currentSlot);
})
.catch((error) => {
console.error('Error:', error);
});
};
const getGenerateRobot = (token: string): void => {
setInputToken(token);
genKey(token)
.then((key) => {
garage.createRobot({
token,
pubKey: key.publicKeyArmored,
encPrivKey: key.encryptedPrivateKeyArmored,
});
void federation.fetchRobot(garage, garage.currentSlot);
})
.catch((error) => {
console.error('Error:', error);
@ -180,7 +194,7 @@ const RobotPage = ({ avatarBaseUrl }: RobotPageProps): JSX.Element => {
badToken={badToken}
inputToken={inputToken}
setInputToken={setInputToken}
getGenerateRobot={getGenerateRobot}
getRecoverRobot={getRecoverRobot}
/>
) : null}
</Paper>

View File

@ -297,16 +297,21 @@ export class Coordinator {
console.log(e);
});
garage.updateRobot(
{
...newAttributes,
tokenSHA256: authHeaders.tokenSHA256,
loading: false,
bitsEntropy,
shannonEntropy,
},
index,
);
if (
newAttributes?.activeOrderId !== null ||
(garage.getRobot(index).activeOrderId === null && newAttributes?.lastOrderId !== null)
) {
garage.updateRobot(
{
...newAttributes,
tokenSHA256: authHeaders.tokenSHA256,
loading: false,
bitsEntropy,
shannonEntropy,
},
index,
);
}
return garage.getRobot(index);
};

View File

@ -102,11 +102,12 @@ export class Federation {
const coordinator = this.coordinators[currentOrder.shortAlias];
if (coordinator != null && currentOrder.id !== null) {
const newOrder = await coordinator.fetchOrder(currentOrder.id, robot);
return {
...currentOrder,
order: newOrder,
};
if (newOrder) {
return {
...currentOrder,
order: newOrder,
};
}
}
}
return currentOrder;

View File

@ -17,10 +17,9 @@ class Garage {
this.slots = rawSlots
.filter((raw: any) => raw !== null)
.map((raw: any) => {
const newSlot: Slot = { robot: new Robot(), order: null };
newSlot.order = raw.order as Order;
newSlot.robot.update(raw.robot);
return newSlot;
const robot = new Robot(raw.robot);
robot.update(raw.robot);
return { robot, order: raw.order as Order };
});
console.log('Robot Garage was loaded from local storage');
}
@ -29,7 +28,8 @@ class Garage {
this.slots = [{ robot: new Robot(), order: null }];
}
this.currentSlot = this.slots.length - 1;
this.currentSlot = 0;
this.hooks = {
onRobotUpdate: [],
onOrderUpdate: [],
@ -73,7 +73,7 @@ class Garage {
deleteSlot: (index?: number) => void = (index) => {
const targetSlot = index ?? this.slots.length - 1;
this.slots.splice(targetSlot, 1);
this.currentSlot = this.slots.length - 1;
this.currentSlot = 0;
this.triggerHook('onRobotUpdate');
this.triggerHook('onOrderUpdate');
this.save();
@ -104,12 +104,12 @@ class Garage {
return this.getSlot(slot).robot;
};
createRobot = (attributes: Record<any, any>): number => {
createRobot = (attributes: Record<any, any>): void => {
const newSlot = { robot: new Robot(), order: null };
newSlot.robot.update(attributes);
this.slots.push(newSlot);
return this.slots.length - 1;
this.currentSlot = this.slots.length - 1;
this.save();
};
// Orders

View File

@ -119,7 +119,7 @@
"i2p": ""
},
"testnet": {
"onion": "https://qu6xztmzhlve6nxbb77jldek53pvhkaltz6seni7wq6g6yyj233qp4yd.onion",
"onion": "https://testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion",
"clearnet": "https://test.unsafe.satstralia.com",
"i2p": ""
},
@ -134,14 +134,14 @@
"color": "#000000",
"testnet": {
"onion": "http://none.onion",
"clearnet": "http://127.0.0.1:12596"
"clearnet": "http://localhost:12596"
},
"badges": {
"donatesToDevFund": 0
},
"mainnet": {
"onion": "http://none.onion",
"clearnet": "http://127.0.0.1:12596"
"clearnet": "http://localhost:12596"
},
"policies": {
"Development Policy": "Don't look around, just buidl"

View File

@ -39,7 +39,7 @@ testnet_temple_socat="socat tcp4-LISTEN:${testnet_temple_port},reuseaddr,fork,ke
mainnet_satstralia_onion=satstraoq35jffvkgpfoqld32nzw2siuvowanruindbfojowpwsjdgad.onion
mainnet_satstralia_port=103
# Testnet
testnet_satstralia_onion=qu6xztmzhlve6nxbb77jldek53pvhkaltz6seni7wq6g6yyj233qp4yd.onion
testnet_satstralia_onion=testraliar7xkhos2gipv2k65obykofb4jqzl5l4danfryacifi4t7qd.onion
testnet_satstralia_port=1003
# socat cmd
mainnet_satstralia_socat="socat tcp4-LISTEN:${mainnet_satstralia_port},reuseaddr,fork,keepalive,bind=127.0.0.1 SOCKS4A:${TOR_PROXY_IP:-127.0.0.1}:${mainnet_satstralia_onion}:80,socksport=${TOR_PROXY_PORT:-9050}"