payment-kit 1.17.12 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,6 @@ import assert from 'assert';
4
4
 
5
5
  import { isEthereumDid } from '@arcblock/did';
6
6
  import { toStakeAddress } from '@arcblock/did-util';
7
- import env from '@blocklet/sdk/lib/env';
8
7
  import { BN, fromUnitToToken, toBN } from '@ocap/util';
9
8
 
10
9
  import { Op } from 'sequelize';
@@ -26,10 +25,6 @@ export async function ensureStakedForGas() {
26
25
 
27
26
  try {
28
27
  const { state: account } = await client.getAccountState({ address: wallet.address });
29
- if (!account) {
30
- const hash = await client.declare({ moniker: env.appNameSlug, wallet });
31
- logger.info(`declared app on chain ${host}`, { hash });
32
- }
33
28
 
34
29
  const address = toStakeAddress(wallet.address, wallet.address);
35
30
  const { state: stake } = await client.getStakeState({ address });
@@ -116,7 +116,7 @@ router.post('/', auth, async (req, res) => {
116
116
  blockNumber,
117
117
  });
118
118
  } catch (err) {
119
- logger.error('verify ethereum api endpoint failed', err);
119
+ logger.error(`verify ${paymentType} api endpoint failed`, err);
120
120
  return res.status(400).json({ error: err.message });
121
121
  }
122
122
 
@@ -295,6 +295,33 @@ router.put('/:id', auth, async (req, res) => {
295
295
  if ('logo' in method.dataValues || raw.logo !== undefined) {
296
296
  updateData.logo = raw.logo ?? method.logo;
297
297
  }
298
+ const updateSettings = 'settings' in req.body ? req.body.settings : null;
299
+ if (EVM_CHAIN_TYPES.includes(method.type as string) && updateSettings) {
300
+ const paymentType = method.type as EVMChainType;
301
+ if (!updateSettings[paymentType]?.api_host) {
302
+ return res.status(400).json({ error: `${paymentType} api_host is required` });
303
+ }
304
+ if (!updateSettings[paymentType]?.explorer_host) {
305
+ return res.status(400).json({ error: `${paymentType} explorer_host is required` });
306
+ }
307
+ if (!updateSettings[paymentType]?.native_symbol) {
308
+ return res.status(400).json({ error: `${paymentType} native_symbol is required` });
309
+ }
310
+ try {
311
+ const provider = new ethers.JsonRpcProvider(updateSettings[paymentType]?.api_host);
312
+ const [network, blockNumber] = await Promise.all([provider.getNetwork(), provider.getBlockNumber()]);
313
+ updateSettings[paymentType]!.chain_id = network.chainId.toString();
314
+ logger.info(`${paymentType} api endpoint verified`, {
315
+ settings: updateSettings[paymentType],
316
+ network,
317
+ blockNumber,
318
+ });
319
+ } catch (err) {
320
+ logger.error(`verify ${paymentType} api endpoint failed`, err);
321
+ return res.status(400).json({ error: err.message });
322
+ }
323
+ updateData.settings = pick(PaymentMethod.encryptSettings(updateSettings), [paymentType]) as PaymentMethodSettings;
324
+ }
298
325
  const updatedMethod = await method.update(updateData);
299
326
  return res.json(updatedMethod);
300
327
  } catch (err) {
package/blocklet.yml CHANGED
@@ -14,7 +14,7 @@ repository:
14
14
  type: git
15
15
  url: git+https://github.com/blocklet/payment-kit.git
16
16
  specVersion: 1.2.8
17
- version: 1.17.12
17
+ version: 1.18.0
18
18
  logo: logo.png
19
19
  files:
20
20
  - dist
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payment-kit",
3
- "version": "1.17.12",
3
+ "version": "1.18.0",
4
4
  "scripts": {
5
5
  "dev": "blocklet dev --open",
6
6
  "eject": "vite eject",
@@ -53,7 +53,7 @@
53
53
  "@arcblock/validator": "^1.19.3",
54
54
  "@blocklet/js-sdk": "^1.16.37",
55
55
  "@blocklet/logger": "^1.16.37",
56
- "@blocklet/payment-react": "1.17.12",
56
+ "@blocklet/payment-react": "1.18.0",
57
57
  "@blocklet/sdk": "^1.16.37",
58
58
  "@blocklet/ui-react": "^2.11.27",
59
59
  "@blocklet/uploader": "^0.1.64",
@@ -121,7 +121,7 @@
121
121
  "devDependencies": {
122
122
  "@abtnode/types": "^1.16.37",
123
123
  "@arcblock/eslint-config-ts": "^0.3.3",
124
- "@blocklet/payment-types": "1.17.12",
124
+ "@blocklet/payment-types": "1.18.0",
125
125
  "@types/cookie-parser": "^1.4.7",
126
126
  "@types/cors": "^2.8.17",
127
127
  "@types/debug": "^4.1.12",
@@ -167,5 +167,5 @@
167
167
  "parser": "typescript"
168
168
  }
169
169
  },
170
- "gitHead": "da4588c387abaed2109c591b8e08661ae90c8f3c"
170
+ "gitHead": "052c301e1f565558766c9346ba355f2fd072108e"
171
171
  }
@@ -11,15 +11,15 @@ import BaseMethodForm from './base';
11
11
 
12
12
  PaymentMethodForm.defaultProps = {
13
13
  action: 'create',
14
- activeKeys: [],
14
+ editableKeys: [],
15
15
  };
16
16
 
17
17
  export default function PaymentMethodForm({
18
18
  action,
19
- activeKeys,
19
+ editableKeys,
20
20
  }: {
21
21
  action?: 'create' | 'edit';
22
- activeKeys?: string[];
22
+ editableKeys?: string[];
23
23
  }) {
24
24
  const { t } = useLocaleContext();
25
25
  const { control, setValue } = useFormContext();
@@ -28,7 +28,7 @@ export default function PaymentMethodForm({
28
28
 
29
29
  const checkDisabled = (key: string) => {
30
30
  if (action === 'edit') {
31
- return !activeKeys?.includes(key);
31
+ return !editableKeys?.includes(key);
32
32
  }
33
33
  return false;
34
34
  };
@@ -151,7 +151,7 @@ Uploader.defaultProps = {
151
151
  preview: '',
152
152
  maxFileSize: undefined,
153
153
  maxNumberOfFiles: 1,
154
- allowedFileExts: ['.png', '.jpeg', '.webp'],
154
+ allowedFileExts: ['.png', '.jpeg', '.webp', '.svg', '.jpg'],
155
155
  disabled: false,
156
156
  };
157
157
 
@@ -63,7 +63,18 @@ export default function PaymentMethodEdit({ onClose, value }: { onClose: () => v
63
63
  </Button>
64
64
  }>
65
65
  <FormProvider {...methods}>
66
- <PaymentMethodForm action="edit" activeKeys={['name', 'description', 'logo']} />
66
+ <PaymentMethodForm
67
+ action="edit"
68
+ editableKeys={[
69
+ 'name',
70
+ 'description',
71
+ 'logo',
72
+ 'settings.base.api_host',
73
+ 'settings.base.explorer_host',
74
+ 'settings.ethereum.api_host',
75
+ 'settings.ethereum.explorer_host',
76
+ ]}
77
+ />
67
78
  </FormProvider>
68
79
  </DrawerForm>
69
80
  );