mirror of
https://github.com/RoboSats/robosats.git
synced 2025-07-21 02:03:14 +00:00
Fix garage deletion (#1085)
This commit is contained in:
@ -65,7 +65,7 @@ const RobotPage = (): JSX.Element => {
|
|||||||
setInputToken(token);
|
setInputToken(token);
|
||||||
genKey(token)
|
genKey(token)
|
||||||
.then((key) => {
|
.then((key) => {
|
||||||
garage.upsertRobot(token, sortedCoordinators[0], {
|
garage.createRobot(token, sortedCoordinators[0], {
|
||||||
token,
|
token,
|
||||||
pubKey: key.publicKeyArmored,
|
pubKey: key.publicKeyArmored,
|
||||||
encPrivKey: key.encryptedPrivateKeyArmored,
|
encPrivKey: key.encryptedPrivateKeyArmored,
|
||||||
|
@ -292,54 +292,60 @@ const BookTable = ({
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const typeObj = useCallback((width: number) => {
|
const typeObj = useCallback(
|
||||||
return {
|
(width: number) => {
|
||||||
field: 'type',
|
return {
|
||||||
headerName: t('Is'),
|
field: 'type',
|
||||||
width: width * fontSize,
|
headerName: t('Is'),
|
||||||
renderCell: (params: any) => {
|
width: width * fontSize,
|
||||||
return (
|
renderCell: (params: any) => {
|
||||||
<div
|
return (
|
||||||
style={{ cursor: 'pointer' }}
|
<div
|
||||||
onClick={() => {
|
style={{ cursor: 'pointer' }}
|
||||||
onOrderClicked(params.row.id, params.row.coordinatorShortAlias);
|
onClick={() => {
|
||||||
}}
|
onOrderClicked(params.row.id, params.row.coordinatorShortAlias);
|
||||||
>
|
}}
|
||||||
{params.row.type === 1
|
>
|
||||||
? t(fav.mode === 'fiat' ? 'Seller' : 'Swapping Out')
|
{params.row.type === 1
|
||||||
: t(fav.mode === 'fiat' ? 'Buyer' : 'Swapping In')}
|
? t(fav.mode === 'fiat' ? 'Seller' : 'Swapping Out')
|
||||||
</div>
|
: t(fav.mode === 'fiat' ? 'Buyer' : 'Swapping In')}
|
||||||
);
|
</div>
|
||||||
},
|
);
|
||||||
};
|
},
|
||||||
}, [fav.mode]);
|
};
|
||||||
|
},
|
||||||
|
[fav.mode],
|
||||||
|
);
|
||||||
|
|
||||||
const amountObj = useCallback((width: number) => {
|
const amountObj = useCallback(
|
||||||
return {
|
(width: number) => {
|
||||||
field: 'amount',
|
return {
|
||||||
headerName: t('Amount'),
|
field: 'amount',
|
||||||
type: 'number',
|
headerName: t('Amount'),
|
||||||
width: width * fontSize,
|
type: 'number',
|
||||||
renderCell: (params: any) => {
|
width: width * fontSize,
|
||||||
const amount = fav.mode === 'swap' ? params.row.amount * 100 : params.row.amount;
|
renderCell: (params: any) => {
|
||||||
const minAmount =
|
const amount = fav.mode === 'swap' ? params.row.amount * 100 : params.row.amount;
|
||||||
fav.mode === 'swap' ? params.row.min_amount * 100 : params.row.min_amount;
|
const minAmount =
|
||||||
const maxAmount =
|
fav.mode === 'swap' ? params.row.min_amount * 100 : params.row.min_amount;
|
||||||
fav.mode === 'swap' ? params.row.max_amount * 100 : params.row.max_amount;
|
const maxAmount =
|
||||||
return (
|
fav.mode === 'swap' ? params.row.max_amount * 100 : params.row.max_amount;
|
||||||
<div
|
return (
|
||||||
style={{ cursor: 'pointer' }}
|
<div
|
||||||
onClick={() => {
|
style={{ cursor: 'pointer' }}
|
||||||
onOrderClicked(params.row.id, params.row.coordinatorShortAlias);
|
onClick={() => {
|
||||||
}}
|
onOrderClicked(params.row.id, params.row.coordinatorShortAlias);
|
||||||
>
|
}}
|
||||||
{amountToString(amount, params.row.has_range, minAmount, maxAmount) +
|
>
|
||||||
(fav.mode === 'swap' ? 'M Sats' : '')}
|
{amountToString(amount, params.row.has_range, minAmount, maxAmount) +
|
||||||
</div>
|
(fav.mode === 'swap' ? 'M Sats' : '')}
|
||||||
);
|
</div>
|
||||||
},
|
);
|
||||||
};
|
},
|
||||||
}, [fav.mode]);
|
};
|
||||||
|
},
|
||||||
|
[fav.mode],
|
||||||
|
);
|
||||||
|
|
||||||
const currencyObj = useCallback((width: number) => {
|
const currencyObj = useCallback((width: number) => {
|
||||||
return {
|
return {
|
||||||
@ -369,30 +375,33 @@ const BookTable = ({
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const paymentObj = useCallback((width: number) => {
|
const paymentObj = useCallback(
|
||||||
return {
|
(width: number) => {
|
||||||
field: 'payment_method',
|
return {
|
||||||
headerName: fav.mode === 'fiat' ? t('Payment Method') : t('Destination'),
|
field: 'payment_method',
|
||||||
width: width * fontSize,
|
headerName: fav.mode === 'fiat' ? t('Payment Method') : t('Destination'),
|
||||||
renderCell: (params: any) => {
|
width: width * fontSize,
|
||||||
return (
|
renderCell: (params: any) => {
|
||||||
<div
|
return (
|
||||||
style={{ cursor: 'pointer' }}
|
<div
|
||||||
onClick={() => {
|
style={{ cursor: 'pointer' }}
|
||||||
onOrderClicked(params.row.id, params.row.coordinatorShortAlias);
|
onClick={() => {
|
||||||
}}
|
onOrderClicked(params.row.id, params.row.coordinatorShortAlias);
|
||||||
>
|
}}
|
||||||
<PaymentStringAsIcons
|
>
|
||||||
othersText={t('Others')}
|
<PaymentStringAsIcons
|
||||||
verbose={true}
|
othersText={t('Others')}
|
||||||
size={1.7 * fontSize}
|
verbose={true}
|
||||||
text={params.row.payment_method}
|
size={1.7 * fontSize}
|
||||||
/>
|
text={params.row.payment_method}
|
||||||
</div>
|
/>
|
||||||
);
|
</div>
|
||||||
},
|
);
|
||||||
};
|
},
|
||||||
}, [fav.mode]);
|
};
|
||||||
|
},
|
||||||
|
[fav.mode],
|
||||||
|
);
|
||||||
|
|
||||||
const paymentSmallObj = useCallback((width: number) => {
|
const paymentSmallObj = useCallback((width: number) => {
|
||||||
return {
|
return {
|
||||||
|
@ -319,7 +319,7 @@ export class Coordinator {
|
|||||||
console.log(e);
|
console.log(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
garage.upsertRobot(token, this.shortAlias, {
|
garage.updateRobot(token, this.shortAlias, {
|
||||||
...newAttributes,
|
...newAttributes,
|
||||||
tokenSHA256: authHeaders.tokenSHA256,
|
tokenSHA256: authHeaders.tokenSHA256,
|
||||||
loading: false,
|
loading: false,
|
||||||
@ -378,7 +378,7 @@ export class Coordinator {
|
|||||||
},
|
},
|
||||||
{ tokenSHA256: robot.tokenSHA256 },
|
{ tokenSHA256: robot.tokenSHA256 },
|
||||||
);
|
);
|
||||||
garage.upsertRobot(slot?.token, this.shortAlias, {
|
garage.updateRobot(slot?.token, this.shortAlias, {
|
||||||
earnedRewards: data?.successful_withdrawal === true ? 0 : robot.earnedRewards,
|
earnedRewards: data?.successful_withdrawal === true ? 0 : robot.earnedRewards,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -400,7 +400,7 @@ export class Coordinator {
|
|||||||
{ tokenSHA256: robot.tokenSHA256 },
|
{ tokenSHA256: robot.tokenSHA256 },
|
||||||
);
|
);
|
||||||
|
|
||||||
garage.upsertRobot(slot?.token, this.shortAlias, {
|
garage.updateRobot(slot?.token, this.shortAlias, {
|
||||||
stealthInvoices: wantsStealth,
|
stealthInvoices: wantsStealth,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -59,10 +59,9 @@ class Garage {
|
|||||||
const rawSlots = JSON.parse(slotsDump);
|
const rawSlots = JSON.parse(slotsDump);
|
||||||
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
|
Object.values(rawSlots).forEach((rawSlot: Record<any, any>) => {
|
||||||
if (rawSlot?.token) {
|
if (rawSlot?.token) {
|
||||||
this.createSlot(rawSlot?.token);
|
|
||||||
Object.keys(rawSlot.robots).forEach((shortAlias) => {
|
Object.keys(rawSlot.robots).forEach((shortAlias) => {
|
||||||
const rawRobot = rawSlot.robots[shortAlias];
|
const rawRobot = rawSlot.robots[shortAlias];
|
||||||
this.upsertRobot(rawRobot.token, shortAlias, rawRobot);
|
this.createRobot(rawRobot.token, shortAlias, rawRobot);
|
||||||
});
|
});
|
||||||
this.currentSlot = rawSlot?.token;
|
this.currentSlot = rawSlot?.token;
|
||||||
}
|
}
|
||||||
@ -79,22 +78,14 @@ class Garage {
|
|||||||
return currentToken ? this.slots[currentToken] ?? null : null;
|
return currentToken ? this.slots[currentToken] ?? null : null;
|
||||||
};
|
};
|
||||||
|
|
||||||
createSlot: (token: string) => Slot | null = (token) => {
|
|
||||||
if (token !== null) {
|
|
||||||
this.slots[token] = new Slot(token);
|
|
||||||
return this.slots[token];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
};
|
|
||||||
|
|
||||||
deleteSlot: (token?: string) => void = (token) => {
|
deleteSlot: (token?: string) => void = (token) => {
|
||||||
const targetIndex = token ?? this.currentSlot;
|
const targetIndex = token ?? this.currentSlot;
|
||||||
if (targetIndex) {
|
if (targetIndex) {
|
||||||
Reflect.deleteProperty(this.slots, targetIndex);
|
Reflect.deleteProperty(this.slots, targetIndex);
|
||||||
this.currentSlot = null;
|
this.currentSlot = null;
|
||||||
|
this.save();
|
||||||
this.triggerHook('onRobotUpdate');
|
this.triggerHook('onRobotUpdate');
|
||||||
this.triggerHook('onOrderUpdate');
|
this.triggerHook('onOrderUpdate');
|
||||||
this.save();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -111,7 +102,22 @@ class Garage {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Robots
|
// Robots
|
||||||
upsertRobot: (token: string, shortAlias: string, attributes: Record<any, any>) => void = (
|
createRobot: (token: string, shortAlias: string, attributes: Record<any, any>) => void = (
|
||||||
|
token,
|
||||||
|
shortAlias,
|
||||||
|
attributes,
|
||||||
|
) => {
|
||||||
|
if (!token || !shortAlias) return;
|
||||||
|
|
||||||
|
if (this.getSlot(token) === null) {
|
||||||
|
this.slots[token] = new Slot(token);
|
||||||
|
this.slots[token]?.createRobot(shortAlias, attributes);
|
||||||
|
this.save();
|
||||||
|
this.triggerHook('onRobotUpdate');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
updateRobot: (token: string, shortAlias: string, attributes: Record<any, any>) => void = (
|
||||||
token,
|
token,
|
||||||
shortAlias,
|
shortAlias,
|
||||||
attributes,
|
attributes,
|
||||||
@ -120,14 +126,10 @@ class Garage {
|
|||||||
|
|
||||||
let slot = this.getSlot(token);
|
let slot = this.getSlot(token);
|
||||||
|
|
||||||
if (slot === null && token) {
|
|
||||||
slot = this.createSlot(token);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (slot != null) {
|
if (slot != null) {
|
||||||
slot.upsertRobot(shortAlias, { token, ...attributes });
|
slot.updateRobot(shortAlias, { token, ...attributes });
|
||||||
this.triggerHook('onRobotUpdate');
|
|
||||||
this.save();
|
this.save();
|
||||||
|
this.triggerHook('onRobotUpdate');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -149,8 +151,8 @@ class Garage {
|
|||||||
} else {
|
} else {
|
||||||
slot.order = null;
|
slot.order = null;
|
||||||
}
|
}
|
||||||
this.triggerHook('onOrderUpdate');
|
|
||||||
this.save();
|
this.save();
|
||||||
|
this.triggerHook('onOrderUpdate');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,16 @@ class Slot {
|
|||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
upsertRobot = (shortAlias: string, attributes: Record<any, any>): Robot | null => {
|
createRobot = (shortAlias: string, attributes: Record<any, any>): Robot | null => {
|
||||||
if (this.robots[shortAlias] === undefined)
|
if (this.robots[shortAlias] === undefined) {
|
||||||
this.robots[shortAlias] = new Robot(attributes ?? {});
|
this.robots[shortAlias] = new Robot(attributes ?? {});
|
||||||
|
return this.robots[shortAlias];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
updateRobot = (shortAlias: string, attributes: Record<any, any>): Robot | null => {
|
||||||
this.robots[shortAlias].update(attributes);
|
this.robots[shortAlias].update(attributes);
|
||||||
|
|
||||||
if (attributes.lastOrderId !== undefined && attributes.lastOrderId != null) {
|
if (attributes.lastOrderId !== undefined && attributes.lastOrderId != null) {
|
||||||
|
Reference in New Issue
Block a user