• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

safe-global / safe-core-sdk / 12008523214

25 Nov 2024 10:55AM CUT coverage: 75.515%. Remained the same
12008523214

push

github

web-flow
feat(protocol-kit): Add react native compatibility (#1033)

241 of 390 branches covered (61.79%)

Branch coverage included in aggregate %.

786 of 970 relevant lines covered (81.03%)

3.76 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

35.0
/packages/sdk-starter-kit/src/BaseClient.ts
1
import Safe, {
2
  AddOwnerTxParams,
3
  RemoveOwnerTxParams,
4
  SwapOwnerTxParams
5
} from '@safe-global/protocol-kit'
6
import SafeApiKit from '@safe-global/api-kit'
7
import { SafeTransaction, TransactionBase } from '@safe-global/types-kit'
8

9
import { ChangeThresholdTxParams } from './types'
10

11
export class BaseClient {
5✔
12
  protocolKit: Safe
13
  apiKit: SafeApiKit
14

15
  constructor(protocolKit: Safe, apiKit: SafeApiKit) {
16
    this.protocolKit = protocolKit
14✔
17
    this.apiKit = apiKit
14✔
18
  }
19

20
  /**
21
   * Returns the Safe address.
22
   *
23
   * @returns {string} The Safe address
24
   */
25
  async getAddress(): Promise<string> {
26
    return this.protocolKit.getAddress()
1✔
27
  }
28

29
  /**
30
   * Checks if the current Safe is deployed.
31
   *
32
   * @returns {boolean} if the Safe contract is deployed
33
   */
34
  async isDeployed(): Promise<boolean> {
35
    return this.protocolKit.isSafeDeployed()
×
36
  }
37

38
  /**
39
   * Checks if a specific address is an owner of the current Safe.
40
   *
41
   * @param {string} ownerAddress - The account address
42
   * @returns {boolean} TRUE if the account is an owner
43
   */
44
  async isOwner(ownerAddress: string): Promise<boolean> {
45
    return this.protocolKit.isOwner(ownerAddress)
×
46
  }
47

48
  /**
49
   * Returns the list of Safe owner accounts.
50
   *
51
   * @returns The list of owners
52
   */
53
  async getOwners(): Promise<string[]> {
54
    return this.protocolKit.getOwners()
1✔
55
  }
56

57
  /**
58
   * Returns the Safe threshold.
59
   *
60
   * @returns {number} The Safe threshold
61
   */
62
  async getThreshold(): Promise<number> {
63
    return this.protocolKit.getThreshold()
1✔
64
  }
65

66
  /**
67
   * Returns the Safe nonce.
68
   *
69
   * @returns {number} The Safe nonce
70
   */
71
  async getNonce(): Promise<number> {
72
    return this.protocolKit.getNonce()
×
73
  }
74

75
  /**
76
   * Returns a list of owners who have approved a specific Safe transaction.
77
   *
78
   * @param {string} txHash - The Safe transaction hash
79
   * @returns {string[]} The list of owners
80
   */
81
  async getOwnersWhoApprovedTransaction(txHash: string): Promise<string[]> {
82
    return this.protocolKit.getOwnersWhoApprovedTx(txHash)
×
83
  }
84

85
  /**
86
   * Encodes the data for adding a new owner to the Safe.
87
   *
88
   * @param {AddOwnerTxParams} addOwnerParams - The parameters for adding a new owner
89
   * @returns {TransactionBase} The encoded data
90
   */
91
  async createAddOwnerTransaction(addOwnerParams: AddOwnerTxParams): Promise<TransactionBase> {
92
    const addOwnerTransaction = await this.protocolKit.createAddOwnerTx(addOwnerParams)
×
93

94
    return this.#buildTransaction(addOwnerTransaction)
×
95
  }
96

97
  /**
98
   * Encodes the data for removing an owner from the Safe.
99
   *
100
   * @param {RemoveOwnerTxParams} removeOwnerParams - The parameters for removing an owner
101
   * @returns {TransactionBase} The encoded data
102
   */
103
  async createRemoveOwnerTransaction(
104
    removeOwnerParams: RemoveOwnerTxParams
105
  ): Promise<TransactionBase> {
106
    const removeOwnerTransaction = await this.protocolKit.createRemoveOwnerTx(removeOwnerParams)
×
107

108
    return this.#buildTransaction(removeOwnerTransaction)
×
109
  }
110

111
  /**
112
   * Encodes the data for swapping an owner in the Safe.
113
   *
114
   * @param {SwapOwnerTxParams} swapParams - The parameters for swapping an owner
115
   * @returns {TransactionBase} The encoded data
116
   */
117
  async createSwapOwnerTransaction(swapParams: SwapOwnerTxParams): Promise<TransactionBase> {
118
    const swapOwnerTransaction = await this.protocolKit.createSwapOwnerTx(swapParams)
×
119

120
    return this.#buildTransaction(swapOwnerTransaction)
×
121
  }
122

123
  /**
124
   * Encodes the data for changing the Safe threshold.
125
   *
126
   * @param {ChangeThresholdTxParams} changeThresholdParams - The parameters for changing the Safe threshold
127
   * @returns {TransactionBase} The encoded data
128
   */
129
  async createChangeThresholdTransaction(
130
    changeThresholdParams: ChangeThresholdTxParams
131
  ): Promise<TransactionBase> {
132
    const changeThresholdTransaction = await this.protocolKit.createChangeThresholdTx(
×
133
      changeThresholdParams.threshold
134
    )
135

136
    return this.#buildTransaction(changeThresholdTransaction)
×
137
  }
138

139
  async #buildTransaction(safeTransaction: SafeTransaction): Promise<TransactionBase> {
5✔
140
    return {
×
141
      to: safeTransaction.data.to,
142
      value: safeTransaction.data.value,
143
      data: safeTransaction.data.data
144
    }
145
  }
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc