@novastera-oss/nitro-metamask 0.7.8 → 0.7.9

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.
package/app.plugin.js CHANGED
@@ -6,82 +6,25 @@ const withMetamaskAppDelegate = (config) => {
6
6
 
7
7
  // Check if AppDelegate is Swift
8
8
  if (modResults.language === 'swift') {
9
- // Migrate stale/incorrect import if present
10
- if (modResults.contents.includes('import metamask_ios_sdk')) {
11
- modResults.contents = modResults.contents.replace(
12
- /import\s+metamask_ios_sdk/g,
13
- 'import NitroMetamask'
14
- );
15
- }
9
+ // Swift AppDelegate should not import Nitro/MetaMask modules directly.
10
+ // Cleanup legacy injected imports from previous plugin versions.
11
+ modResults.contents = modResults.contents.replace(
12
+ /^\s*import\s+metamask_ios_sdk\s*\n?/gm,
13
+ ''
14
+ );
15
+ modResults.contents = modResults.contents.replace(
16
+ /^\s*import\s+NitroMetamask\s*\n?/gm,
17
+ ''
18
+ );
16
19
 
17
- // Add NitroMetamask import if not present
18
- if (!modResults.contents.includes('import NitroMetamask')) {
19
- // Find the last import statement and add after it
20
- const importRegex = /^import\s+.*$/gm;
21
- const imports = modResults.contents.match(importRegex);
22
- if (imports && imports.length > 0) {
23
- const lastImport = imports[imports.length - 1];
24
- const lastImportIndex = modResults.contents.lastIndexOf(lastImport);
25
- modResults.contents =
26
- modResults.contents.slice(0, lastImportIndex + lastImport.length) +
27
- '\nimport NitroMetamask' +
28
- modResults.contents.slice(lastImportIndex + lastImport.length);
29
- } else {
30
- // No imports found, add at the top after the first line
31
- const firstLineIndex = modResults.contents.indexOf('\n');
32
- modResults.contents =
33
- modResults.contents.slice(0, firstLineIndex + 1) +
34
- 'import NitroMetamask\n' +
35
- modResults.contents.slice(firstLineIndex + 1);
36
- }
37
- }
20
+ // Optional migration cleanup: remove legacy injected MetaMask handler
21
+ // block if it exists in Swift AppDelegate files.
22
+ modResults.contents = modResults.contents.replace(
23
+ /\n\s*\/\/ Handle deep links from MetaMask wallet[\s\S]*?MetaMaskSDK\.sharedInstance\?\.handleUrl\(url\)[\s\S]*?return false\s*\n\s*\}/g,
24
+ ''
25
+ );
38
26
 
39
- // Check if the method already exists
40
- if (modResults.contents.includes('MetaMaskSDK.sharedInstance?.handleUrl')) {
41
- return config;
42
- }
43
-
44
- // Add the deep link handler method
45
- const deepLinkHandler = `
46
- // Handle deep links from MetaMask wallet
47
- // MetaMask returns to the app via deep link after signing/connecting
48
- // Added by @novastera-oss/nitro-metamask config plugin
49
- func application(
50
- _ app: UIApplication,
51
- open url: URL,
52
- options: [UIApplication.OpenURLOptionsKey: Any] = [:]
53
- ) -> Bool {
54
- // Check if this is a MetaMask deep link (host="mmsdk")
55
- if let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
56
- components.host == "mmsdk" {
57
- // Handle MetaMask deep link return
58
- MetaMaskSDK.sharedInstance?.handleUrl(url)
59
- return true
60
- }
61
-
62
- // Handle other deep links (e.g., React Native Linking)
63
- return false
64
- }`;
65
-
66
- // Insert before the last closing brace of the AppDelegate class
67
- // Try to find the closing brace of the class before @end or end of file
68
- const classEndPattern = /(\s+)\}(?=\s*(?:@end|$))/;
69
- const match = modResults.contents.match(classEndPattern);
70
- if (match) {
71
- const indent = match[1];
72
- const insertIndex = match.index;
73
- modResults.contents =
74
- modResults.contents.slice(0, insertIndex) +
75
- deepLinkHandler.replace(/^ /gm, indent) +
76
- '\n' + indent + '}' +
77
- modResults.contents.slice(insertIndex + match[0].length);
78
- } else {
79
- // Fallback: append before @end
80
- modResults.contents = modResults.contents.replace(
81
- /^(@end|}$)/m,
82
- deepLinkHandler + '\n$1'
83
- );
84
- }
27
+ return config;
85
28
  } else if (modResults.language === 'objc') {
86
29
  // Handle Objective-C AppDelegate
87
30
  // Remove stale direct SDK import if present. Importing MetaMaskSDK headers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@novastera-oss/nitro-metamask",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "description": "Native mobile MetaMask wallet integration for React Native. Part of Novastera CRM/ERP platform ecosystem. Provides secure authentication and message signing for Web3 mobile applications.",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
@@ -5,22 +5,15 @@ jest.mock('@expo/config-plugins', () => ({
5
5
  const withMetamaskAppDelegate = require('../../app.plugin.js')
6
6
 
7
7
  describe('app.plugin.js', () => {
8
- it('replaces stale Swift import even if handler already exists', () => {
8
+ it('removes stale Swift imports and does not inject handler', () => {
9
9
  const config = {
10
10
  modResults: {
11
11
  language: 'swift',
12
12
  contents: `import UIKit
13
13
  import metamask_ios_sdk
14
+ import NitroMetamask
14
15
 
15
16
  class AppDelegate: NSObject {
16
- func application(
17
- _ app: UIApplication,
18
- open url: URL,
19
- options: [UIApplication.OpenURLOptionsKey: Any] = [:]
20
- ) -> Bool {
21
- MetaMaskSDK.sharedInstance?.handleUrl(url)
22
- return true
23
- }
24
17
  }
25
18
  `,
26
19
  },
@@ -29,12 +22,12 @@ class AppDelegate: NSObject {
29
22
  const result = withMetamaskAppDelegate(config)
30
23
  const contents: string = result.modResults.contents
31
24
 
32
- expect(contents).toContain('import NitroMetamask')
33
25
  expect(contents).not.toContain('import metamask_ios_sdk')
34
- expect((contents.match(/MetaMaskSDK\.sharedInstance\?\.handleUrl\(url\)/g) || []).length).toBe(1)
26
+ expect(contents).not.toContain('import NitroMetamask')
27
+ expect(contents).not.toContain('MetaMaskSDK.sharedInstance?.handleUrl(url)')
35
28
  })
36
29
 
37
- it('injects NitroMetamask Swift import when missing', () => {
30
+ it('keeps Swift AppDelegate untouched apart from cleanup', () => {
38
31
  const config = {
39
32
  modResults: {
40
33
  language: 'swift',
@@ -49,8 +42,9 @@ class AppDelegate: NSObject {
49
42
  const result = withMetamaskAppDelegate(config)
50
43
  const contents: string = result.modResults.contents
51
44
 
52
- expect(contents).toContain('import NitroMetamask')
53
- expect(contents).toContain('MetaMaskSDK.sharedInstance?.handleUrl(url)')
45
+ expect(contents).toContain('import UIKit')
46
+ expect(contents).not.toContain('import NitroMetamask')
47
+ expect(contents).not.toContain('MetaMaskSDK.sharedInstance?.handleUrl(url)')
54
48
  })
55
49
 
56
50
  it('migrates Objective-C direct SDK usage to runtime-safe calls', () => {