From: Ardis Lu Date: Tue, 13 Aug 2024 06:01:28 +0000 (-0700) Subject: Handle edge cases for non-Safe smart contracts X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=2702eae19a413c688276e25ef83563ba486cc9a9;p=safe-owners Handle edge cases for non-Safe smart contracts Older multi-signatures used `required()` instead of `getThreshold()`. Also handled non-multi-sig smart contracts with early exit. --- diff --git a/index.html b/index.html index 084351f..73c9528 100644 --- a/index.html +++ b/index.html @@ -194,13 +194,31 @@ }, 'safe' ] + }, + { + jsonrpc: '2.0', + id: 'required', + method: 'eth_call', + params: [ + { + to: safe, + data: '0xdc8452cd' // required() + }, + 'safe' + ] } ]) }).then(r => r.json()); - const { owners, threshold } = response.reduce((a, c) => ({ ...a, [c.id]: c.result }), {}); + const { owners, threshold, required } = response.reduce((a, c) => ({ ...a, [c.id]: c.result }), {}); + if (owners === undefined) { // Smart contract reverted + return { + owners: [safe], + threshold: -1 // Sentinel value for non Safe smart contract + } + } return { owners: [...owners.replace('0x', '').substring(128).matchAll(/.{64}/g)].map(o => `0x${o[0].substring(24)}`), - threshold: parseInt(threshold) + threshold: Number.isNaN(parseInt(threshold)) ? parseInt(required) : parseInt(threshold) } } @@ -210,6 +228,10 @@ root.insertAdjacentHTML('beforeend', `
  • ${safe}
  • `); return; } + else if (threshold === -1) { + root.insertAdjacentHTML('beforeend', `
  • ${safe} (Unknown smart contract)
  • `); + return; + } root.insertAdjacentHTML('beforeend', `
  • ${safe} (${threshold}-of-${owners.length})
  • `); const newRoot = document.createElement('ul'); root.querySelector('li:last-child').insertAdjacentElement('beforeend', newRoot);