Skip to content

Commit 8415cca

Browse files
committed
feat: support read-only address url param
1 parent a6e4d20 commit 8415cca

File tree

6 files changed

+325
-114
lines changed

6 files changed

+325
-114
lines changed

package.json

+11-9
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@
1717
"dependencies": {
1818
"@agoric/casting": "^0.4.3-u13.0",
1919
"@agoric/cosmic-proto": "^0.3.0",
20-
"@agoric/ertp": "^0.16.2",
20+
"@agoric/ertp": "^0.16.3-u16.1",
2121
"@agoric/inter-protocol": "^0.16.1",
22-
"@agoric/rpc": "^0.9.0",
22+
"@agoric/rpc": "^0.10.0",
2323
"@agoric/smart-wallet": "^0.5.3",
2424
"@agoric/ui-components": "^0.9.0",
2525
"@agoric/wallet": "^0.18.3",
26-
"@agoric/web-components": "^0.15.0",
26+
"@agoric/web-components": "^0.16.0",
2727
"@agoric/zoe": "^0.26.2",
28-
"@endo/eventual-send": "^1.0.1",
29-
"@endo/init": "^1.0.1",
30-
"@endo/marshal": "^0.8.9",
28+
"@endo/eventual-send": "^1.2.5",
29+
"@endo/init": "^1.1.4",
30+
"@endo/marshal": "^1.5.3",
3131
"@headlessui/react": "^1.6.6",
3232
"clsx": "^1.2.1",
3333
"framer-motion": "^7.2.1",
@@ -42,7 +42,7 @@
4242
"react-router-dom": "^6.4.5",
4343
"react-toastify": "^9.1.1",
4444
"react-view-slider": "^4.5.0",
45-
"ses": "^1.3.0",
45+
"ses": "^1.8.0",
4646
"zustand": "^4.1.5"
4747
},
4848
"devDependencies": {
@@ -77,6 +77,8 @@
7777
"resolutions": {
7878
"**/@agoric/xsnap": "0.14.3-u14.0",
7979
"**/@agoric/time": "0.3.3-u14.0",
80-
"**/@agoric/vats": "0.15.2-u15.0"
81-
}
80+
"**/@agoric/vats": "0.15.2-u15.0",
81+
"**/@endo/pass-style": "1.4.3"
82+
},
83+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
8284
}

src/components/ConfigureNewVault.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { maxIstToMintFromVault } from 'utils/vaultMath';
2020
import LeapLiquidityModal, { Direction } from './leap-elements/LiquidityModal';
2121
import { useMemo } from 'react';
22+
import { NatValue } from '@agoric/ertp/src/types';
2223

2324
const maxIstWarning =
2425
'Warning: This will create a vault with the lowest possible collateralization ratio which greatly increases your risk of liquidation if there are downward price movements.';
@@ -103,7 +104,7 @@ const ConfigureNewVault = () => {
103104
selectedMetrics.totalDebt,
104105
AmountMath.makeEmpty(selectedParams.debtLimit.brand),
105106
selectedParams.mintFee,
106-
AmountMath.make(collateralBrand, valueToLock),
107+
AmountMath.make(collateralBrand, valueToLock ?? 0n),
107108
collateralPrice,
108109
selectedParams.inferredMinimumCollateralization,
109110
lockedPrice,
@@ -126,7 +127,7 @@ const ConfigureNewVault = () => {
126127
return;
127128
}
128129

129-
setValueToLock(purse.currentAmount.value);
130+
setValueToLock(purse.currentAmount.value as NatValue);
130131
};
131132

132133
const onMaxDebtClicked = () => {

src/components/NewVaultOfferSummary.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,8 @@ const NewVaultOfferSummary = () => {
184184

185185
const createVault = async () => {
186186
setIsProvisionDialogOpen(false);
187+
assert(depositAmount);
188+
assert(mintAmount);
187189
await makeOpenVaultOffer(depositAmount, mintAmount, () =>
188190
setIsVaultCreationDialogOpen(true),
189191
);
@@ -218,7 +220,7 @@ const NewVaultOfferSummary = () => {
218220
return 'Create Vault';
219221
}, [chainConnection, vaultLimitReached]);
220222

221-
const debtBalanceInfo = debtBalance && (
223+
const debtBalanceInfo = debtBalance ? (
222224
<Popover className="inline absolute -right-5 top-[3px]">
223225
<Popover.Button className="text-base">
224226
<HiOutlineInformationCircle />
@@ -242,6 +244,8 @@ const NewVaultOfferSummary = () => {
242244
</Popover.Panel>
243245
</Transition>
244246
</Popover>
247+
) : (
248+
''
245249
);
246250

247251
return (

src/service/wallet.ts

+25-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ import {
66
ChainConnection,
77
} from 'store/app';
88
import { toast } from 'react-toastify';
9-
import {
10-
makeAgoricWalletConnection,
11-
AgoricKeplrConnectionErrors as Errors,
12-
} from '@agoric/web-components';
9+
import { makeAgoricWalletConnection, Errors } from '@agoric/web-components';
1310
import type { Id as ToastId, ToastContent, ToastOptions } from 'react-toastify';
1411

1512
const watchPurses = (chainConnection: ChainConnection) => {
@@ -76,6 +73,25 @@ type ConnectionError = {
7673

7774
const autoCloseDelayMs = 7000;
7875

76+
const getReadOnlyAddressFromUrlParams = () =>
77+
new URLSearchParams(window.location.search).get('address');
78+
79+
const makeReadOnlyClientConfig = (address: string) => {
80+
return {
81+
address,
82+
client: {
83+
getSequence: () => 0,
84+
signAndBroadcast: (_address: string, msgs: unknown[], _fee: unknown) => {
85+
console.log('Messages to sign copied below:');
86+
console.log(msgs);
87+
throw new Error(
88+
'Cannot sign message in read-only mode. See previous console log for message contents.',
89+
);
90+
},
91+
},
92+
};
93+
};
94+
7995
export const makeWalletService = () => {
8096
let stopWatchingPurses: () => void;
8197
let stopWatchingPublicSubscribers: () => void;
@@ -91,6 +107,8 @@ export const makeWalletService = () => {
91107
toastId = toast.error(content, options);
92108
};
93109

110+
const readOnlyAddress = getReadOnlyAddressFromUrlParams();
111+
94112
const connect = async (shouldCheckDisclaimer = true) => {
95113
const {
96114
isWalletConnectionInProgress,
@@ -113,6 +131,7 @@ export const makeWalletService = () => {
113131
appStore.setState({ isWalletConnectionInProgress: true });
114132
try {
115133
assert(rpcNode);
134+
assert(chainStorageWatcher);
116135
const connection = await makeAgoricWalletConnection(
117136
chainStorageWatcher,
118137
rpcNode,
@@ -125,6 +144,8 @@ export const makeWalletService = () => {
125144
(e instanceof Error ? `: ${e.message}` : ''),
126145
),
127146
),
147+
// @ts-expect-error Fake clientConfig for special read-only mode.
148+
readOnlyAddress ? makeReadOnlyClientConfig(readOnlyAddress) : undefined,
128149
);
129150
appStore.setState({ chainConnection: connection });
130151
stopWatchingPurses = watchPurses(connection);

src/utils/vaultMath.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import type {
1919
VaultMetrics,
2020
VaultParams,
2121
} from 'store/vaults';
22-
import type { Amount, Brand, NatValue } from '@agoric/ertp/src/types';
22+
import type {
23+
Amount,
24+
Brand,
25+
NatAmount,
26+
NatValue,
27+
} from '@agoric/ertp/src/types';
2328

2429
export const isLiquidationPriceBelowGivenPrice = (
2530
locked: Amount<'nat'>,
@@ -74,9 +79,12 @@ export const computeToLock = (
7479
};
7580

7681
/**
77-
* @returns tuple of [value of difference, boolean of whether it's negative]
82+
* Returns [value of difference, boolean of whether it's negative]
7883
*/
79-
export const netValue = (lockedValue: Amount<'nat'>, debt: Amount<'nat'>) =>
84+
export const netValue = (
85+
lockedValue: Amount<'nat'>,
86+
debt: Amount<'nat'>,
87+
): [NatAmount, boolean] =>
8088
AmountMath.isGTE(lockedValue, debt)
8189
? [AmountMath.subtract(lockedValue, debt), false]
8290
: [AmountMath.subtract(debt, lockedValue), true];

0 commit comments

Comments
 (0)